Sometimes we have to put some PDF file or images which we want to download directly from the website. So, for this reason, we have to create a download button or attribute which provide our users to directly download files from the website.
Here we learn how to create the download button or attribute in HTML.
Example : Code for the download button
<a href="/images/myimage.jpg" download>
<img src="/images/myimage.jpg" alt="downloadimage" width="104" height="142">
You can use this code on your website, just change the image location and image name.
We create a download image if anyone wants to download the image, they just want to click on the image and the image starts downloading automatically.
Definition and Usage
The download attribute specifies that the target will be downloaded when a user clicks on the hyperlink.
This attribute is only used if the href attribute is set.
The value of the attribute will be the name of the downloaded file. There are no restrictions on allowed values, and the browser will automatically detect the correct file extension and add it to the file (.img, .pdf, .txt, .html, etc.).
If the value is omitted, the original filename is used.