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.