Categories
HTML

How to download a PDF file instead of opening them in browser when clicked?

Spread the love

Sometimes, we want to download a PDF file instead of opening them in browser when clicked.

In this article, we’ll look at how to download a PDF file instead of opening them in browser when clicked.

How to download a PDF file instead of opening them in browser when clicked?

To download a PDF file instead of opening them in browser when clicked, we can add the download attribute to the link.

For instance, we write

<a href="http://link/to/file" download="FileName">Download it!</a>

to set the download attribute of the anchor element to the file name of file when we download it.

Then when we click on the link, the file will be downloaded.

Conclusion

To download a PDF file instead of opening them in browser when clicked, we can add the download attribute to the link.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

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