HTML - download Attribute



The HTML download attribute is used to specify that the resource( the file or resource specified in the href attribute) will be downloaded when a user clicks on the hyperlink.

It indicates that the hyperlink is to be used to download the resource. You can pass the resource in the href attribute that the user can download, which can be any image file, GIF file, video file, etc.

Syntax

Following is the syntax of download attribute −

<tag download></tag>

Example

In the following example, we are using the download attribute within the <a> tag to indicate the hyperlink is used for downloading resources.

<!DOCTYPE html>
<html lang="en">
<head>
   <title>HTML 'download' attribute</title>
</head>
<body>
   <!--HTML 'download' attribute-->
   <p>Example of the HTML 'download' attribute</p>
   <p>Click on below link: </p>
   <a href="https://www.tutorialspoint.com/html/images/html-mini-logo.jpg" download>Download</a>
</body>
</html>

On running the above code, the output window will pop up, displaying the text along with a hyperlink on the webpage. when the user clicks on the hyperlink the event gets triggered and downloads the image.

Example

Consider the another scenario, where we are going to use the download attribute with the area tag.

<!DOCTYPE html>
<html lang="en">
<head>
   <title>HTML 'download' attribute</title>
</head>
<body>
   <!--HTML 'download' attribute-->
   <p>Example of the HTML 'download' attribute</p>
   <p>Click on below image to download it: </p>
   <img src="https://www.tutorialspoint.com/images/logo.png?v3" alt="" usemap="#demo">
   <map name="demo" src="https://www.tutorialspoint.com/images/logo.png?v3">
      <area shape="rect" coords="34,44,270,350" href="html logo.jpg" alt="" download>
   </map>
</body>
</html>

When we run the above code, it will generate an output consiting of the text along with a image on the webpage. when the user clicks on the image the event gets triggered and downloads the image.

Example

In this example, we use the 'download' attribute within the <a> tag to make the link downloadable. We specify the resource of the GIF file as a value of href attribute, so the GIF will be downloaded when the user clicks on the download link.

<!DOCTYPE html>
<html lang="en">
<head>
   <title>HTML 'download' attribute</title>
   <style>
      a {
         padding: 10px;
         background-color: green;
         color: white;
         text-decoration: none;
      }
   </style>
</head>
<body>
   <!--HTML 'download' attribute-->
   <p>Example of the HTML 'download' attribute</p>
   <p>Click on below link to download GIF: </p>
   <a href="giphy.gif">Download</a>
</body>
</html>

On running the above code, the output window will pop up displaying the text along with the hyperlink on the webpage. when the user clicks the link the event gets triggered and downloads the giffy.

html_attributes_reference.htm
Advertisements