«   Previous tip Next tip   »

HTML: Help users to download files with the HTML download attribute

Last updated: 29th March 2023

Introduction

If you add a download attribute on an anchor tag, the browser will download the resource!

<a download href="octopus.jpg">Download octopus pic</a>

The browser can use the image URL as a default file name for the downloaded file, or you can specify an attribute value e.g. octopus.jpg which configures the file name of the downloaded file.

Bonus tip

If you use an attribute value with slashes, like this:

<a download="some/long/path/picture.jpg">Download</a>

The browser downloads the file as some_long_path_picture.jpg - a little tip worth knowing about.

This works with other file types too, like .json. Try it out - it works in all modern browsers.

«   Previous tip Next tip   »

Sign up to receive a developer tip, in the form of a gif, in your inbox each week