How to use the download attribute

ThumbnailHTML5 came with all new APIs, new input types and attributes for forms. As is often the case, those major additions often obscure the minor upgrades and I think that this is particularly true of the download attribute.

As you know, there are some files that the browser doesn’t automatically download; images, other web pages and depending on the settings in your browser, sometimes even PDFs. The download attribute gives the browser a native way to download these files automatically, without having to fall back on JavaScript. This is really useful for any app that deals with the downloading of images, such as image upload sites.

Using the download attribute

Since the download attribute doesn’t use scripts of any kind, it’s as simple as adding the attribute to your link:

<a href="myFolder/myImage.png">Download image</a>

What’s great about this attribute is that you can even set a name for the downloadable file, even when it’s not the name on your server. This is great for sites with complex file names, or even dynamically created images, that want to provide a simple and user-friendly file name. To provide a name, you just add an equals sign, followed by the name you want to use surrounded in quotes, like so:

<a href="myFolder/reallyUnnecessarilyLongAndComplicatedFileName.png">Download image</a>

Note that the browser will automatically add the correct file extension to the downloaded file, so you don’t need to include that inside your attribute value.

 

Browser support

Currently, only Chrome 14+ and Firefox 20+ support the download attribute, so you may need to fall back on some simple JavaScript to detect if the attribute is supported. You can do so like this:

var a = document.createElement('a');

if(typeof a.download != "undefined")
{
   // download attribute is supported
}
else
{
  // download attribute is not supported
}

 

Conclusion

Taking into consideration everything that has been added to HTML5, the download attribute is a very small part, but in my opinion it’s an attribute that was long overdue, and definitely has its uses in today’s apps for both usability and simplification.

 

Have you implemented the download attribute? What are your unsung heroes of HTML5? Let us know in the comments.

Featured image/thumbnail, download image via Shutterstock.

1,600+ Awesome Photoshop Presets – only $27!

Source

Posted in Blog | Comments Off on How to use the download attribute

21 Inspiring Clean Website Designs

Advertise here with BSA

It’s always nice to browse some nice and clean websites. It is a good way to get inspiration for future projects and also to see how designers are delivering clean designs. Today we gathered some inspiring examples to show you that clean layouts don’t need to be plain and boring, you can have colors, textures, illustrated elements and much more. Remember that the concept of clean design is to have something simple, striped from allegories and unnecessary elements, not something boring. So check out the examples we have here and let us know what you think of them.

living edge

21 Inspiring Clean Website Designs

Shane Prendergast

21 Inspiring Clean Website Designs

Wallmob

21 Inspiring Clean Website Designs

Wootten

21 Inspiring Clean Website Designs

Oli Llisher

21 Inspiring Clean Website Designs

Pitchbox

21 Inspiring Clean Website Designs

Thankful

21 Inspiring Clean Website Designs

kippt

21 Inspiring Clean Website Designs

Studio Brun

21 Inspiring Clean Website Designs

Coastal Conservation League

21 Inspiring Clean Website Designs

Peachey Photography

21 Inspiring Clean Website Designs

Richard Photo Lab

21 Inspiring Clean Website Designs

mixpanel

21 Inspiring Clean Website Designs

Joyride Coffee Distributors

21 Inspiring Clean Website Designs

Lars Tornoe

21 Inspiring Clean Website Designs

Knock Knock Factory

21 Inspiring Clean Website Designs

Cedric Vella

21 Inspiring Clean Website Designs

Amy Woodside

21 Inspiring Clean Website Designs

Instrument

21 Inspiring Clean Website Designs

Michiel de Draaf

21 Inspiring Clean Website Designs

The Clocksmiths

21 Inspiring Clean Website Designs

Posted in Blog | Comments Off on 21 Inspiring Clean Website Designs