Force a Download with HTML5

HTML5 is the greatest version of HTML ever! (Well, at least until the next awesome version comes out). I just learned how trivially easy it is to force downloads with HTML5.

I was just trying to force a download of a PDF file because the customers need to sign it and send it back and it’s harder to do that online. I was going to use JavaScript, but decided that I’d do a quick search in case there was a better way.

Forcing Downloads is Easy—HTML5 to the Rescue!

Not only is there a better way, but it’s trivially easy to implement. I just add the keyword download to my anchor and BAM! the browser will pop a dialog box. I haven’t tested it in a lot of browsers (or devices), but it’s still huge! I mean, as a fallback I can attach a download function only to links that have the download keyword in them.

Now my download links look like this:

<a href="link to file" download="">Download the PDF</a>

I’m practically crying, I love HTML5 so much!!!

HTML for RWD—Learn the HTML You Need in a Free Chapter

Sams Teach Yourself Responsive Web Design in 24 Hours
Sams Teach Yourself Responsive Web Design in 24 Hours

While responsive web design uses CSS to adjust web designs to respond to the devices viewing the page, you need to start with good HTML. Chapter 5 of my latest book Sams Teach Yourself Responsive Web Design in 24 Hours helps you learn the basics of HTML so that you’re ready to create a responsive website.

In chapter 5, you will learn:

  • How to write HTML for RWD
  • How to build a basic web page with HTML5
  • What semantic elements are and how to use them
  • Why valid HTML is important

And this chapter is available for free on the Informit website.

Note that if you’re a complete novice to HTML, this chapter will only be a starting place. It’s intended as an introduction to the minimum HTML you might need to do RWD. If you need to learn HTML, you should check out my first Sams book: Sams Teach Yourself HTML5 in 24 Hours (get a copy).

HTML5 Learning Lab Available

HTML5 Learning Lab
HTML5 Mobile Application Development in 24 Hours Learning Lab

I’m pleased to announce that the latest version of my book Sams Teach Yourself HTML5 Mobile Application Development in 24 Hours is available in a Learning Lab format from Pearson.

The Learning Lab takes the entire book and adds interactive quizzes, videos, step-by-step lessons, and live code editing right in the book. If you’ve wanted to do more practice while learning HTML5, this is an excellent version of the book to get.

Three Free Chapters

The first three chapters are available online for free for you to try out and see if this version will work for you.

I worked hard on these videos and on the quizzes as well as writing the entire body of text, so I hope that you enjoy the HTML5 Learning Lab.


Latest Zeen issue is now live

Teach Yourself HTML5 Zeen - Issue #2
Teach Yourself HTML5 Zeen – Issue #2

I’ve posted the second issue of my HTML5 Zeen today. There are a few things that are wonky with the issue, most notably that Zeen says it’s “Issue #3” when it’s #2. But whatever.

In this issue I show you some ways to get started with HTML5 if you haven’t already. Including the cover image which shows you the basics for what you need to write to create an HTML5 document.

Writing HTML5 is Really Easy

All it takes is a DOCYTPE:

<!doctype html>

And you’ve got an HTML5 document. One thing that most people forget is that HTML5 is not a new language. It’s evolved from HTML 4.01 and HTML 3.2 and all the versions before. So if you’re writing HTML 4.01 today, you can start writing HTML5 by just changing one line of your HTML. Don’t worry about changing anything else.

The Zeen issue goes into more detail about dealing with older browsers like IE8 and using editors like Dreamweaver to write your HTML5, but at the end of the day, just putting up the new doctype is all it takes. Poof! You are using the most up-to-date specification. That didn’t hurt a bit!