HTML download Attribute

The HTML download attribute indicates that a linked resource is intended to be downloaded rather than opened through normal navigation. It can be used by itself or given a value that suggests a filename for the downloaded file.

Syntax

The download attribute is placed on an <a> or <area> element that creates a hyperlink.

<a href="sample.txt" download>Download Sample File</a>

When the link is activated, the browser treats the linked resource as a download instead of using normal hyperlink navigation.

Attribute Value

The download attribute can be used without a value or with a value that provides a suggested filename.

Value Description
No value Indicates that the linked resource is intended to be downloaded. The browser determines an appropriate filename.
Filename Provides a suggested filename for the downloaded resource.
<a href="sample.txt" download="example.txt">Download Sample File</a>

Elements That Use the download Attribute

The download attribute can be used with the <a> and <area> elements when they create hyperlinks.

Element Description
<a> Indicates that the resource referenced by the hyperlink is intended to be downloaded.
<area> Indicates that the resource linked from an image map area is intended to be downloaded.

Suggesting a Filename

A value assigned to download provides a suggested filename for the downloaded resource.

<a href="sample.txt" download="html-example.txt">Download Sample File</a>

The browser may adjust the suggested filename when necessary to make it valid for the user's operating system. A filename supplied by the server can also take precedence over the filename suggested by the attribute.

Same-Origin and Cross-Origin Downloads

The download attribute works most predictably with resources from the same origin as the page. Browsers place additional restrictions on cross-origin downloads for security reasons.

For a cross-origin resource, the server may need to explicitly identify the response as a download with an appropriate Content-Disposition HTTP header. Browser behavior can also depend on the resource, response headers, and user settings.

Server Response Headers

HTTP response headers can affect how a downloaded resource is handled. In particular, the Content-Disposition header can identify a response as an attachment and can provide its own filename.

Content-Disposition: attachment; filename="sample.txt"

If the server supplies filename information, it can override the filename suggested by the HTML download attribute.

Common Mistakes

Do not assume that the value of download specifies where the file will be stored. The browser and the user's settings determine the download location.

Do not include a directory path in the suggested filename. Browsers determine where downloaded files are stored and may sanitize characters that are unsuitable for filenames.

Do not assume that download will force every cross-origin resource to download. Cross-origin downloads are subject to additional browser security rules and server response headers.

Browser Support

Baseline: Widely available indicates a feature has been supported by core browsers for at least 30 months. At this stage, the feature is considered stable and safe for most websites to use without needing to worry about compatibility issues or fallbacks, as it is supported by the vast majority of users' devices and browser versions.

The download attribute is widely supported on links in current core browsers. Download behavior can still depend on the URL, response headers, browser security rules, and user settings.

Checking Browser Support

For current browser compatibility information, visit Can I Use? . Search for the HTML element or attribute you want to check. You can also narrow your search by entering an element name and attribute name separated by a colon. Search results can include related HTML features, element attributes, input types, APIs, and other technologies, so select the result that most closely matches the feature you are checking.

Try the download Attribute

The example provides a normal link and a download link to the same file so you can compare their behavior.

Play in Editor

Summary

The HTML download attribute indicates that a hyperlink is intended to download its resource rather than navigate to it. It can be used on <a> and <area> elements, and an optional value can suggest a filename. Server response headers, browser security rules, and user settings can affect the final download behavior.