HTML a Tag download Attribute Tutorial

In this section, we will see what download attribute is and how it works in HTML.

What is download Attribute in HTML <a> Tag?

The download attribute of the HTML <a> tag specifies that the target file (the URL we set for the href attribute) should be downloaded and stored in the users’ devices when users click on the link.

HTML download Attribute in <a> Tag Syntax:

<a download = "filename">

<a> Tag download Attribute Value

The value that we set for the download attribute is the filename that we want it to have when it’s downloaded and stored in the user’s device.

You should know that this value is optional and if we omit the value, browsers will use the name of the file itself to store it in the users’ devices.

Example: using download attribute in HTML <a> tag

See the Pen using download attribute in HTML <a> tag by Omid Dehghan (@odchan1) on CodePen.

Here the name of the file specified in the href attribute is “site-logo” but because the value of the download attribute is set to “enjoyTutorialsLogo”, the file will be saved with this name and not “site-logo”. But if the download attribute didn’t have any value, in that case the name “site-logo” would be chosen for the stored file in the user’s device.

Leave a Reply