How to specify that the target will be downloaded by on click in HTML5 ?
In this article, we will learn how to define that a hyperlink will lead to a download instead of navigating to it when clicked in HTML5. This can be used in cases where content is needed to be downloaded when the link is clicked, like a text file or image hosting service.
The <a> element has an attribute download that is used to specify if the hyperlink would be used to download the linked resource, that is, the value specified with the href attribute instead of navigating to it. It has an optional value that can be used to specify the name of the file that would be downloaded. If this value is not used then the original file name would be used instead.
<a href="file_to_download.jpg" download="filename">
The below examples illustrate the download attribute to specify the target would be downloaded.
Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML course.