← #51 Filter file types of a file input
#52

Create a download link

Topics: HTML

It's common to use an a tag to create a download link. The browser will open the file for some well-supported file types, such as image, pdf, etc.

If you want to enforce the browser to download the file, then use the HTML 5 download attribute. The value of attribute, if specified, will be used as the name of download file.

<!-- Download instead of openning it -->
<a href="/assets/document.pdf" download>

<!-- Download it with new file name -->
<a href="/assets/document.pdf" download="a copy of document.pdf">

It's worth noting that the download attribute only works if the file belongs to the same domain as the current website. It doesn't have effect if the href attribute has the different origin to the site.

Fix a typo or suggest an improvement
#53 Inspect an element shown on hover