HTML <a> with download Attribute

You are Here:

HTML <a> with download Attribute

The download attribute is used to download a URL instead of navigating to it.

Note: The download attribute works only when the href attribute is set.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <img src="/wikimass.png" width="150" height="150"> <br> <a href="/wikimass.png" download>click here to download.</a> </body> </html>

Download attribute with Value

Note: The value for download attribute is Optional.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <img src="/wikimass.png" width="150" height="150"> <br> <a href="/wikimass.png" download="book">click here to download.</a> </body> </html>

Safe Usage

Though most of the modern browser supports download attribute, very few old browsers like Internet Explorer will not support download attribute. So its developer's duty to notify user either to update or to switch their browser to download your file.

In the following example, we will check whether the browser supports download attribute or not by using JavaScript.

Request: If possible, open this page in internet explorer and Run the following example.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <img src="/wikimass.png" width="150" height="150"> <br> <a href="/wikimass.png" download onclick="checkDownload()">click here to download.</a> <script> var hyperlink = document.createElement("a"); // Check if user browser does not supports download attribute function checkDownload(){ if(hyperlink.download === undefined) alert("Sorry, Your browser doesn't support download attribute"); else alert("click OK to download the image"); } </script> </body> </html>

Attribute Value

ValueExplanation
file_nameSpecifies the name of the file to be downloaded.
The value for the download attribute is Optional.

Reminder

Hi Developers, we almost covered 99.5% of HTML Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in HTML.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author