English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML reference manual

HTML tag大全

HTML: <a> download attribute

Usage of <a> download attribute, online instances demonstrating how to use <a> download attribute, browser compatibility, syntax definition, and detailed introduction of its attribute values, etc.

HTML <a> tag

Online examples

Download the file when clicking the link (instead of navigating to the file):

<!doctype html>
<html>
<head>
<title>Usage of the download attribute in html: <a> tag - Basic Tutorial(oldtoolbag.com)</title>/title>
</head>
<body>
<p>Click w3codebox's logo for downloading images</p>
<a href="/static/images/logo.png" download>
  <img src="/static/images/logo.png" alt="oldtoolbag.com" width="150" height="50">
</a>
</body>
</html>
Test and see ‹/›

Note: Edge version12, IE, Safari 10(or earlier versions) or Opera version12(or earlier versions) do not support the download attribute.

Browser compatibility

The numbers in the table indicate the version number of the first browser that supports this attribute.

element




download14.013.020.010.115.0

Definition and usage

The download attribute specifies the target to be downloaded when the user clicks on the hyperlink.
This attribute is only used when the href attribute is set.
The value of this attribute will be the name of the downloaded file. There are no restrictions on the allowed values, and the browser will automatically detect the correct file extension and add it to the file (.img, .pdf, .txt, .html, etc.).
If the value is omitted, the original filename will be used.

HTML 4.01 and HTML5 Difference between

The download attribute is an HTML5New <a> tag attribute added in the middle.

Syntax

        <a download="filename">

Attribute value

ValueDescription
filenameSpecify the file name.

More examples

Specify a value for the download attribute, which will be the new filename for the downloaded file ("w",3codeboxlogo.png” instead of “views.png”

<!doctype html>
<html>
<head>
<title>Usage of the download attribute in html: <a> tag - Basic Tutorial(oldtoolbag.com)</title>/title>
</head>
<body>
<a href="/static/images/logo.png" download="w3codeboxlogo>
  <img src="/run/html/views.png" alt="Views" width="300" height="200">
</a>
<p>Please note that the filename of the downloaded file will be saved as “w3codeboxlogo.jpg” instead of “views.png”./p>
</body>
</html>
Test and see ‹/›

HTML <a> tag