HTML5 Apps: What, Why, and How

HTML5 Apps: What, Why, and How

Tutorial Details
  • Program: HTML
  • Difficulty: Intermediate
  • Estimated Completion Time: 1 hour
This entry is part 13 of 14 in the HTML5 and You Session
« PreviousNext »

If you want to build web apps, you might want to think about using HTML5. HTML5 is the new hotness when it comes to app development, and it has the potential to change the way software is made and sold. It also activates the millions of people out there who know how to make web pages, and never thought their skill set could be used for something else. But before jumping into development, there are some things you should know about HTML5. In this tutorial, I’ll teach you the basics!

What is HTML5?

HTML5 is a W3C spec in the making.

It started at WHATWG, and is the future gold standard for HTML. If you have been around for awhile, you many know that XHTML 2 was the next major version, but that fell apart. The reasons are varied, but one main point of contention was that few websites use perfect syntax, and XHTML 2 was going to enforce perfect syntax. It has also always been extremely hard to say exactly what perfect syntax is. When the browser vendors realized how hard it was going to be to make the switch to XHTML 2, things just broke down.

At that point a bunch of people broke away from the W3C and started the WHATWG. These guys wanted to rethink not just HTML, but the whole standards making process. They started work on a new HTML5 standard. They operated from the principal that there is no perfect, and it’s not their job to tell the world how to do HTML. Instead they focused on looking at what was happening in the real world of HTML.

They also took the time to codify some conventions that sprung up in the community. That is where a lot of the new elements in the HTML5 spec (like the progress bar, video, and audio tags) came from. People have been making due, and they just wanted to make specific pieces of markup to help people do what they have already been doing.

Besides just markup, the WHATWG started creating some new JavaScript APIs. This is where HTML5 started to look “app”-like. They created standards for offline data storage, and an offline application cache, so that whole apps could be stored offline. They also started new working groups around widgets and device access (for using devices like cameras and accelerometers).

An interesting side note to the whole standards process is this: for awhile the differences in rendering engines were so great that one approach to be cross-browser compliant was to sniff which browser the user was on and deliver a different experience based on that.

The WHATWG and others always thought that browser sniffing wasn’t such a good idea. What is commonly recommend now is progressive enhancement. In a nutshell, progressive enhancement is this. Instead of just deciding that one browser would get experience Y and another would get experience Z, why not detect advanced feature support and build up to a great experience? If, at any point, the browser doesn’t support advanced feature X, the user would just get the default experience.

The Last Numbered Spec

This leads to another point about the HTML5 spec: it will probably be the last numbered spec. In the future, instead of revving HTML versions, like HTML6, the W3C will just maintain the latest version of HTML, and there will be a gold standards spec. Web developers can use progressive enhancement to handle the fragmentation, while waiting for browser vendors to catch-up to the spec.

So What are HTML5 Apps?

With HTML5 defined, what is an HTML5 app?

Essentially, a HTML5 app uses all the shiny, new pieces of the HTML5 draft to create an app-like experience.

This means storing data offline, being functional, and acting like a real app instead of just being content for perusal. You probably use web apps now, like Gmail. Gmail actually has an HTML5 version; if you visit Gmail on an iPhone or iPad, you can check it out.


Why Should I Use HTML5?

Why would I want to use HTML5 instead of Objective-C, Flash, Silverlight, or some other kind of device-specific environment? First, there are a couple reason not to use HTML5.

  1. If I was making the latest, greatest 3D shoot-em-up, I would not use HTML5. It just doesn’t have the rich graphics libraries needed to make intense games like those; however, they are working on standards to allow 3D graphics programs into the browser.
  2. If you need to use the camera on devices, or local files system, HTML5 would not be the best choice. There are workarounds, using a native wrapper, which I will discuss shortly, and there are also some standards coming that will help with that.

While there are specific cases for not using HTML5, many apps that get produced today for iOS and Android could work just as easily in HTML5. Besides just technically being able to do it, there are other good reasons to use HTML5.

You Already Know How to Use It

Right now, if you are a web developer, you have all the tools you need to get into this. HTML5 app development is only little more then changing how you think about webpages. In some instances you can just add a few lines to your HTML, and add some stuff on your server and you will have a full, working, offline HTML5 app.

The more we work with standards, the more useful they become.

Besides, web developers already understand cross-browser problems. While there will be more cross-browser issues than ever, web developers have a distinct advantage over other kinds of developers, because they already have this in their pocket. The other part of cross-browser development is standards. The more we work with standards, the more useful they become. Web developers have led the charge in some respect, and now it’s paying off. Instead of having to learn a whole other non-standards-compliant add-on, you can simply rely on what standards bodies have been working towards.

Finally, when it comes to writing code, it can be difficult to see that you might also be doing something political.

When you look at how a handset manufacturer handles itself, and how it chooses to lock in its developers, by choosing to work outside that system you are supporting the notion of freedom.

It’s a small notion, but it matters, because in the long run we want our handset developers to be open, and let us hack on them as much as we want.


How can I use HTML5?

Actually using HTML5 isn’t that hard. It can range from a couple lines of code, to writing a whole new app. Here are a few ways to get started.


1. Create a Mobile Friendly Website

Many websites are only a few tweaks away from a friendlier mobile experience. The first thing to do is take a look at the viewport.

<html>
    <head>
        <meta name="viewport" content="user-scalable=no, width=device-width"/>
    </head>

The viewport meta tag is not a standard yet, but it is a widely accepted convention. Many mobile browsers use this tag to setup certain aspects of web page rendering.

More info on viewport, check out the following documentation:

Besides just the viewport, make sure that your webpages are flexible; for example, use dynamic widths, instead of static widths. Mobile devices are all shapes and sizes, just like browser windows. Designing with the idea of flexibility in mind will automatically make your web pages more mobile-friendly.

The Doctype

A great little tidbit about the next version of HTML5 is this: the doctype went the way of the dodo. It still has to be there, because of many reasons, but it’s been shriveled to mean almost nothing.

<!DOCTYPE html>

This is awesome. No longer do we have to copy and paste a long string of text, because who can remember that thing, anyway?


2. Take Your Website Offline

Some browsers now implement the application cache. The application cache allows you to tell the browser in advance what resources a web page will need offline. The browser will then download those files for offline usage. When the client goes offline the browser will refer to those cached resources.

The application cache isn’t something that you can do by just changing your markup, though. You will need the ability to change the content-type headers on the server. To do that in Apache, you can either put this in a configuration file, or in a .htaccess file.

AddType text/cache-manifest manifest

Once you do that, you can add the following markup to your html element in your webpage. You can call your manifest anything you want, but make sure it’s at the root of your site, and it ends with a .manifest.

<html manifest="my.manifest">

Then, you can create your manifest file. Simply list all the pieces you will need while you are offline. You can’t put cross-domain files here and you won’t want to list anything that changes often. Here is an example manifest file.

CACHE MANIFEST

# Version 1

my.html
my.css
my.js
my.png

When you have this all setup, check it out in a browser that supports the application cache.

If you need to update a resource, just change the manifest file. Even adding a comment will prompt the browser to update the application cache.

The application cache is notoriously hard to debug. This book has some good methods for checking your application cache status.


3. Make Your Videos Accessible Everywhere

If you host video content on your site, and use a flash player to play it, you’re missing out on an opportunity to display video to people using the iOS devices and phones that don’t support flash (which is most phones).

HTML5 has two new tags that make displaying multimedia easier: audio and video. Here is an example video tag.

<video src="myvideo.mp4" controls />

Now, if you want to support as many browsers as possible, you will need to encode your content in a couple different formats. Then, list them like so.

<video poster="myvideo.jpg" controls>
    <source src="myvideo.m4v" type="video/mp4" />
    <source src="myvideo.ogg" type="video/ogg" />
    <embed src="/to/my/video/player"></embed>
</video>

This makes sure that your content can be seen in Firefox, Safari, Chrome, and mobile phones. Finally, for browsers that don’t support the video tag, you can still fallback to a flash player. When a browser doesn’t support a tag, it will usually just not deal with it, and continue recursing till it finds a tag it does know. In this fashion, if you put the embed or object inside the video tag, a browser like IE will use the object. However, a browser that supports the video tag will ignore the embedded flash.


Conclusion: Start Using HTML5 Tags Today

Tags like header, footer, nav, aside, article, and section are nice because they are semantic. They inform webpage consumers a little bit about your intentions for your content. It’s nice to use them. In the future, they will be more helpful than they are now, but there is nothing to stop you from using them today.

Some browsers, like IE, will “freak out” if you use these new tags, but don’t worry. IE does support adding tag types to the DOM, you just need to inform IE about them. To fix this, Remy Sharp created the HTML5 Shiv. If you include this in the head of your webpage, in an IE conditional comment, your page will render just fine.

Now you are using semantically useful HTML!


Bonus: Sell your Apps in an App Store

Yes, right now, you can take your HTML5 apps and sell them on the mobile app stores. Two projects are helping people develop “native” mobile apps, using nothing more then HTML, JavaScript, and CSS. Check these out:

Alternatively, our very own CodeCanyon, within the next month, will be launching a new category for HTML5 apps. In this category, we’ll be selling everything from advanced and custom video players, to libraries, to presentation apps.

To prepare for the category, we’ve launched a competition with $7000 worth of prizes. You have two weeks left to enter, if that interests you!


Wrapping Up

There should be nothing stopping you from exploring HTML5, and if you wanted to be ahead of the game, you should be building HTML5 apps right now. Thanks for reading!


About the Author

Alex Kessinger is a front-end web developer who currently works for Yahoo!

Add Comment

Discussion 40 Comments

  1. krike says:

    Looks like i’m on the right path :) already started using the header, footer,… tags. Thank you for the html5shim tip :) didn’t know about that.

    however about the doctype, i don’t mind using it but should I still add a fallback for the browsers who don’t support that kind of doctype yet?

  2. Zlatan Halilovic says:

    Oh gosh, how I love reading articles on nettuts+. There’s something about this website that makes it so irresistible to me :)

    Oh, yeah, I almost forgot: thanks to the author for writing this excellent article and to the founders of nettuts+ for being so awesome :D

  3. The viewport tip is priceless. Just tried it out on my iPhone and it works like a dream. Hello mobile site development!

  4. w1sh says:

    As much as I’d like to start using HTML5 today, it seems like some browser (looking at you IE) will just explode if they don’t have JS on.

    Anyone ready to start a HFM IE-Bashing campaign on non-client sites yet?
    http://laughingsquid.com/overly-judgemental-internet-explorer-6-splash-pages/

  5. Enthused says:

    Its the functionality and well written articles that keep me glued.

  6. esranull says:

    good post thanks a lot

  7. HTML5 Hold tight I’m coming, everything here is devine thank you!

  8. Jonas says:

    Unless you’re actually planning to make money off your HTML5 smart phone app, please don’t put in an app store. Instead, put it on the Web where pages/apps are to supposed to be anyway.

  9. With XHTML2 being out of the picture, don’t see many other routes the web could take as far as the standard mark-up language is concerned. I’ve always been excited for HTML5, just wasn’t sure if it was safe to jump in with all my future projects. I’ll keep an eye on these develops, nice article.

  10. We’ve already started implementing HTML5 for select projects! @Alex, I thought I was the only one who pasted doc tags!

  11. Steve Maggs says:

    I have to admit to really liking XHTML and its insistence on correct closing of tags, consistency etc. HTML5 does seem to be more democratic somehow and has added some exciting possibilities for people (like me) who never thought they could build an app as the article points out.

    I just hope the predictions about mobile browsing taking over aren’t true, designing for small screens isn’t fun really, the only things that look better small are insects and spots!

  12. flashmac says:

    viewport eh? I’ll have to look into that. Didnt know about it.

  13. Grant says:

    What’s with that iOS being ‘most phones’? It is a clear and distant third to RIM and Android: http://www.npd.com/press/releases/press_100804.html

    On one hand you recommend using conventions like ‘viewport’ but then advocate against using the conventional flash player because Apple won’t support it.

    “When you look at how a handset manufacturer handles itself, and how it chooses to lock in its developers, by choosing to work outside that system you are supporting the notion of freedom.” I couldn’t agree more, but suggesting that we should stay away from Flash because Apple won’t play nice seems to undermine this statement quite a bit.

    And while Steve Jobs may have his reasons for not supporting flash: http://www.apple.com/hotnews/thoughts-on-flash/

    Youtube has their reasons for sticking with it:
    http://apiblog.youtube.com/2010/06/flash-and-html5-tag.html

    Besides all of this, you are recommending serving a video 4 different ways that default to flash instead of just using the convention. The need to do this will eventually drop as the major browsers (except Safari — big surprise: http://diveintohtml5.org/video.html) adopt support for webM, but lets switch when this actually makes sense. Is it really a good/practical idea to create 3 different video files for every video you might have? Maybe for the novelty of it all, but I doubt it’s appealing to someone who hasn’t/can’t automate the process.

  14. I’m such a big fan of XHTML’s clean less, that I’ve been holding off trying HTML5 on my sites, even though I’ve read up on it extensively. Plus, I really thought we were moving away from browser hacks, which is just what the shiv is.

    • David Turner says:

      The shiv exists to add support for the IE browsers that don’t acknowledge the elements HTML5 is adding in. It is, I hope, just a temporary fix, especially with the progress being made with IE9.

      As for being a fan of XHTML’s cleanliness, HTML5 allows you to continue coding in exactly the same way as you do with XHTML. I personally prefer the XHTML layout in terms of code – everything that I open gets closed etc. I still use it and have been working with HTML5 code (though only some small aspects of it) for just under a year now.

  15. I am trying to be positive about HTML5.

    The problem is that I am yet to see a consistent implementation from browser vendors. Chrome has the best support of all but nobody else supports the same set of features the same way that Chrome does. The W3C dumped Web SQL for IndexedDB. While I think this was the right move, many vendors had already implemented Web SQL. The video format cannot be decided upon either.

    I am really excited about the potential that WebWorkers and WebSockets bring. WebGL is also very enticing. However, with WebGL, you still have to do a lot of the same computations that you do in OpenGL. Just now you’re doing them in the browser with JavaScript. I don’t think that HTML5 in these cases (although some of these specification are not part of HTML5 proper) makes things any better or even easier.

    The standard needs a lot of work and what I think will happen is that the industry will gravitate toward a defacto standard and the W3C will have to fall in line. I believe this is what happened with C++. This of course means that we can’t plan for anything because this industry-created standard has no timeline. We just know (hope) it will be agreed upon long before 2022.

  16. Simon says:

    Am I the only one who does not care about HTML5 just yet because there is so long to go until it’s a standard? To be honest, I’m kind of sick of seeing HTML5 articles popping up everywhere when in the real development world (outside of the hobby coders) there is no place for HTML5 at the moment.

    • Tomas says:

      Agree fully. But this is how internet works, HTML5 is the buzzword and everyone just follow. I understand the publishers, its smart marketing and SEO. I think a lot of people are just desperate and therefor jump on something new that promise everything. But when people are back to reality they will see how bad it is. The demos sucks. It’s like Flash 10 years ago. But anyway, its exciting about the mobile development and what going to happen in future.

  17. David Turner says:

    Out of interest, is there a reason that the WebM codec wasn’t included in the HTML5 video element? It seems to be the option that Opera, Firefox and Chrome are leaning… seems a bit odd to see it left out.

  18. Grant says:

    Don’t forget IE9. But to add my 2 cents, I think it may be because WebM is too new. They could have gone with Theora too, but I just don’t think they felt sure of anything specific.

  19. zac says:

    Well, I am convinced! :) Excellent article and the idea of code being a political tool is great. I totally agree. Where is that quote from?

  20. Great article. Let it become the new standard! :D

  21. Ian says:

    There are an awful lot of naysayers out there with regards to HTML5. The good thing about using it is that it degrades gracefully on browsers that do not support it (I’m looking at you Internet Explorer < 9) so everything still works. As long as you test your code on a good selection of browsers, which you're doing anyway, right?

  22. Alexander says:

    I didn’t know there was a market for HTML5 apps. Makes me wanna actually learn it. Thanks!
    And with IE9 actually supporting HTML5, this is going to work out great.

  23. Jaspal Singh says:

    HTML5 is great, powerful, but it is still under development. wait for final version release.
    Thanks for sharing the article on HTML5.

  24. Great article about HTML5. Useful basic info. Thanks.

  25. jimmy says:

    So, do I have to learn html than html5? or i can go straight to HTML5.

  26. Gopal Juneja says:

    It’s a good idea to use HTML5 from today very much, but does it make sense to use JS for the structure of an application. JS dependency is not a good approach.

  27. nick says:

    Android now has more sold than iphone, so it looks like most phones will play flash, the iphone is the only smart phone that wont it looks like…. hmmmm…. I would love to have an iphone, but it’s just not powerful enough, hope iphone 5 has apple being a lot less stingy.

  28. achint verma says:

    HtMl5 has the potential to change the web to it’s better.
    It is cross browser compatible, support 3D, mobile friendly and also gud Geo-locator..
    for more interesting stuff related to HTML5 click here…
    http://www.facebook.com/html5apps

  29. Erik Forey says:

    Más información de HTML 5 en esta página de Microsoft, está muy completa http://www.w3.org/html/logo/

Add a Comment

To add a code snippet to your comment, please wrap your code like so: <pre name="code" class="html">YOUR CODE</pre>. You can replace the class name with "js," "css," "sql," or "php." If there are any "<" or ">" within your code, please search and replace them with: &lt; and &gt; respectively.