HTML Hyperlink Download Attribute

The download attribute of the <a> tag is new in HTML5. What is allows you to do is specify a target, a file, that will be downloaded when a visitor clicks on the hyperlink. This is useful if you are linking to a file that is auto generated but you want the file to be consistently downloaded as the same name. An example of this would be:

<a href="" download="">Download WordPress</a>

In the example, a generated file of is created. This file contains a build of the latest published version of WordPress. However, means nothing to the visitor, so you want the file to be downloaded as the software name, which in this case is wordpress, which we defined in the download attribute of the link example.

You can also use the download attribute to force file downloads. This is also extremely useful, as you would normally have to create code or define force download on the server side, which is tricky as you may force all file extensions to be downloaded. To give you an example, let’s say that you have created a file called README.txt, which contains instructions a individual should read before using a application or software.

<a href="">Read Instructions</a>

When a individual clicked on the hyperlink above, the browser would open the README.txt file. The file would not download; it would just display in the browser. However, with the download attribute, we could force the file to download.

Browser Support

The download attribute works in Chrome, Firefox and Opera (versions newer than 12). Therefore, the download attribute is not supported by Internet Explorer, Safari or Opera versions 12 and earlier.

Download Attribute Usage

Since the download attribute works off of the href attribute, the href attribute must be defined and set.

The download attribute file name and file extension can be different from the file name and file extension set in the href attribute, although in order to work, they should be using the same program type.

If the file extension is omitted from the download attribute, the file extension will be taken from the href attribute, i.e.

<a href="" download="instructions">Read Instructions</a>

README.txt would be downloaded as instructions.txt.