Anchor download attribute

Definition and usage

download Attribute sets or returns the link download attribute value.

download The attribute specifies that the target will be downloaded when the user clicks on the hyperlink.

Note:The download attribute is a new attribute of the <a> element in HTML5.

Example

Example 1

Display the download attribute value of the link:

var x = document.getElementById("myAnchor").download;

Try it yourself

Example 2

Change the value of the download attribute of the link:

document.getElementById("myAnchor").download = "newValue";

Try it yourself

Syntax

Return the download attribute:

anchorObject.download

Set the download attribute:

anchorObject.download = filename

Attribute value

Value Description
filename

Specify the text used as the file name.

If omitted, the original file name will be used.

Note:No file extension needs to be specified - the browser will automatically detect the correct file extension and add it to the file, such as .img, .pdf, .txt, .html, and so on.

Technical Details

Return Value: A string value representing the name of the file to be downloaded.

Browser Support

The numbers in the table indicate the first browser version to fully support this attribute.

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Supported 12.0 Supported Not Supported 15.0

Related Pages

HTML Reference Manual:HTML <a> download Attribute