Sometimes, we want to trigger a file download when clicking an HTML link.
In this article, we’ll look at how to trigger a file download when clicking an HTML link.
How to trigger a file download when clicking an HTML link?
To trigger a file download when clicking an HTML link, we set the download
attribute.
For instance, we write
<a href="url" download="filename">Download</a>
to set the download
attribute to the file name of the downloaded file.
The href
attribute is set to the file URL.
Conclusion
To trigger a file download when clicking an HTML link, we set the download
attribute.