Force links to download in HTML

This one’s really easy and with a bonus on naming the file at the end too.

If you want a file to download instead of opening in the browser, you just add a download attribute to the anchor tag.

<a href="download_this.pdf" download>Download PDF</a>

It doesn’t have to be a PDF, it could be any file.

In one of the tools on my website, I populate the href attribute with a data URL of an SVG QR code.

These data URL files don’t have a name by default and you can set one like this.

<a href="data:image/jpeg;base64..." download="Filename.jpg">Download PDF</a>

Share