- HTML Tutorial
- HTML - Home
- HTML - History and Evolution
- HTML - Overview
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Headings
- HTML - Paragraphs
- HTML - Quotations
- HTML - Comments
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Style Sheet
- HTML - CSS Classes
- HTML - CSS IDs
- HTML - Images
- HTML - Image Map
- HTML Tables
- HTML - Tables
- HTML - Headers & Caption
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Iframes
- HTML - Blocks
- HTML Backgrounds
- HTML - Backgrounds
- HTML Colors
- HTML - Colors
- HTML - RGB
- HTML - HEX
- HTML - HSL
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Code Builder
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
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.
To Continue Learning Please Login
Login with Google