HTML <a> download attribute
Definition and usage
download
attribute specifies the target to be downloaded when the user clicks on the hyperlink (href attribute specified in the file).
download
The optional values of the attribute will become the new name of the file after download. Any value can be used, and the browser will automatically detect the correct file extension and add it to the file (such as .img, .pdf, .txt, .html, etc.).
If the value is omitted, the original filename will be used.
Example
Example 1
Download the file when clicking the link (instead of navigating to the file):
<a href="/logo/w3logo-5.png" download>
Example 2
Specify the value of the download attribute, which will be the new filename of the downloaded file (for example, using "w3logo.jpg" instead of "mycodew3csimage.jpg"):
<a href="/logo/w3logo-5.png" download="w3logo">
Syntax
<a download="filename">
Attribute Value
Value | Description |
---|---|
filename | Optional. Specifies a new filename for the downloaded file. |
Browser Support
The numbers in the table indicate the first browser version that fully supports this attribute.
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
14.0* | 18.0 | 20.0* | 10.1 | 15.0 |
* Chrome 65+ and Firefox only support same-origin download links.