The download attribute of the link tags in HTML

šŸ“– Neural networks for Javascript developers

The Neural Networks for JavaScript developers book is almost ready! Learn the basics of AI with TensorFlowJs examples. Join now the presale and get a 15$ coupon off the launching price!

Cool stuff learned today! For any a anchor tag we can add the download attribute and that link becomes a download link instead of a navigational one.

<a href="/my-file.pdf" download >
    Download the file 
</a>

It works with any type of file. You can download images, pdfs, documents, you name it!

Hot to Create a Downloadable Link using the Download Attribute in HTML

Please note that the download attribute only works for same-origin files. You can just use files from your own domain to isolate potentially malicious threats.

Setting a name for the downloaded file when using the download attribute

If you just add the download attribute to an a tag then the file that is downloaded will have the same name as the file in the href attribute.

<a href="/my-file.pdf" download>
    Download with the same name
</a>
<!-- original file: my-file.pdf
     downloaded file:  my-file.pdf -->

But, we can set up a new name for the downloaded file by giving a value to the download attribute:

<a href="/my-file.pdf" download="manual.pdf">
    Download with a different name
</a>
<!-- original file: my-file.pdf
     downloaded file:  manual.pdf -->

Note that even if it's possible to set the extension in the file, it's much better not to add it. If you just type the new filename, without the extension, the original extension will be kept. This is especially useful when working with images.

<a href="/avatar.png" download="picture">
    Download with a different name, keep the file extension
</a>
<!-- original file: avatar.png
     downloaded file:  picture.png -->

šŸ“– Neural networks for Javascript developers

The Neural Networks for JavaScript developers book is almost ready! Learn the basics of AI with TensorFlowJs examples. Join now the presale and get a 15$ coupon off the launching price!


Leave a Reply

Your email address will not be published. Required fields are marked *

Home Screencasts Best of Newsletter Search X

Neural Networks for JavaScript developers
Presale - 15$ free coupon

Hi friend! Before you go, just wanted to let you know that in March 2023 I will be launching the TensorFlow.Js by Example course.

This course will include basic concepts of AI and Neural Networks done with TensorFlowJs such as:

  • Working with datasets
  • Visualizing training
  • Deep Neural Networks in JavaScript
  • Reinforcement Learning
  • Convolutional neural networks
  • and much more ...

Also, there will be a lot of examples as:

  • Object detection
  • Natural language processing
  • Face and voice recognition
  • Gaming AI

Join now the waiting list and get a 15$ coupon off the launching price!

X