Categories
HTML

How to trigger a file download when clicking an HTML link?

Spread the love

Sometimes, we want to trigger a file download when clicking an HTML link.

In this article, we’ll look at how to trigger a file download when clicking an HTML link.

How to trigger a file download when clicking an HTML link?

To trigger a file download when clicking an HTML link, we set the download attribute.

For instance, we write

<a href="url" download="filename">Download</a>

to set the download attribute to the file name of the downloaded file.

The href attribute is set to the file URL.

Conclusion

To trigger a file download when clicking an HTML link, we set the download attribute.

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 *