Tip: Customize the names of downloadable files

Angelos Chalaris · Jan 11, 2021 ·

Webdev, Html, Browser

HTML5 introduced a variety of convenient features that many of us use every day. As downloadable links aren't something I work with very often, I recently found out that you can use the download attribute on an <a> element for much more than just making it trigger a download. In fact, you can pass it a string value that will act as the name of the downloadable file, effectively allowing you to customize its name:

<!-- The downloaded file will be named 'June-2020.csv' -->
<a href="/data/2020/06/report.csv" download="June-2020.csv">June 2020</a>

Image credit: Frank R on Unsplash

Recommended snippets