Back to Top

How to use HTML5 download attribute?

html5 download

For the first time, HTML5 introduced new interactive features to the HTML.This HTML5 attribute provides a functionality of a force download.

Mostly you use a link for the file like images, pdf, documents, texts and generally when clicking on the link, files will be open within the browser’s new tab.HTML5 download attribute within links change behavior and allow the file to download in the browser.Basically, this attribute specifies the browser to download files rather than open the target resource in the new tab of the browser .

Initially in older browser you need to write php code to download files and this approach is very annoying so HTML5 added new download properties to change it. It can be used like this:

Here, In download attribute set the property values, you can specify the name of the resource file you want to allow to download.The value of the download attribute is a not necessary and no restrictions but make sure that its a filename.The attribute value specifies the filename that used when downloading the file.Here I used “filename” filename, not “filename.jpg” because no need to specify the file extension if you want to preserve the original name.

Through this attribute browser will download the file. You can also pass the attribute value as the null, like this:

At present, this property has been supported in major browsers.

This is not fiction, it actually work so use this HTML5 feature and enjoy its benefits.

NOTE: Firefox does not support automatic download if you are using different domain.It will work for same domain of file and current page.

That’s it.you are done it 🙂 Thank you for reading.Feel free to share your thoughts! Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.

Comments (4)

  1. Atribute download only show icon ?

  2. This is only to show icon.This attribute is used to forcefully download content when click on link or button.

  3. We have created a demo page for you to see this attribute in action. HTML5 has introdued some new elements and attributes that make life easier for web developers.

    1. Dyson, Where you have created demo? Yeah,you are absolutely right! new elements make life easier 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

How to use Short Hand Array in PHP

Posted on 9 years ago

Bhumi

How to use Index in MySQL

Posted on 9 years ago

Bhumi

Control Flow Functions in MySQL

Posted on 9 years ago

Bhumi