1
05/05/2021 1:02 pm
Topic starter
How to download a file using HTML
This topic was modified 4 years ago by CodeWithBishal-admin
1 Answer
1
05/05/2021 1:49 pm
Topic starter
HTML Download attribute
The HTML download attribute is used to download any file.
<a href="" download>Download a file</a>
This will download the particular file given in the [ href="" ] attribute.
For example:
<a href="https://discuss.codewithbishal.com/wp-content/uploads/2021/05/pexels-michael-block-3225517.jpg" download>Download the picture</a>
the above code will be rendered by the browser as:
If you want to download the same file with other extensions like .jpg, .png, .jpeg, and with a custom name; you can easily achieve this by the below code:
<a href="https://discuss.codewithbishal.com/wp-content/uploads/2021/05/pexels-michael-block-3225517.jpg" download="Picture.jpeg">Download the picture as PDF</a>
Which will be rendered by the browser as:
Similarly,
<a href="https://discuss.codewithbishal.com/wp-content/uploads/2021/05/pexels-michael-block-3225517.jpg" download="Picture.png">Download the picture as PNG</a>
Will be rendered by the browser as:
Photo by Michael Block from Pexels
This post was modified 4 years ago 4 times by CodeWithBishal-admin