[Solved] How to download a file using HTML

  

1
Topic starter

How to download a file using HTML

This topic was modified 1 year ago by codewithbishal - Admin
Topic Tags
1 Answer
1
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:

Download the picture as JPG

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:

 Download the picture as JPEG

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:

Download the picture as PNG 

Photo by Michael Block from Pexels

This post was modified 1 year ago 4 times by codewithbishal - Admin