Five HTML5 Techniques to Learn Now
No doubt about it: HTML5 is hot stuff. A year or two ago it was esoteric and unripe; now it's necessary. But does it still make you uncomfortable?
Your hesitation is understandable: Parts of HTML5 are still years away from completion, and other parts involve programming concepts that were entirely absent from front-end work up through HTML4. Don't let those realities intimidate you, though. You can and should take your first HTML5 steps today!
HTMLDOC and Validation: The Easiest Leap Forward
As this article demonstrates, your first few steps will be easy to apply immediately, they'll likely improve your HTML right away, and they won't demand that you learn any client-side scripting or programming. Before you do anything else, for instance, learn how to upgrade existing HTML to HTML5, as well as create new HTML5 source.
You probably already have source that looks like this:
<html> <head> <title>The Title</title> </head> <body> ... </body> </html>
If so, you should transform it to look more like this:
<!DOCTYPE html> <html> <head> <title>The Title</title> </head> <body> ... </body> </html>
Simple enough, right?
As tiny as this change appears at first, it has significant benefits:
- Essentially all pertinent browsers, even those from before the year 2000, recognize this DOCTYPE as a marker of standards-based source. This puts them on their best behavior in regard to minimization of vendor-specific interpretations.
- You can validate your source as HTML5. Have you ever validated your HTML source? It's a great thing to do, and becomes even better with HTML5.
The advantages of HTML5 validation are actually a bit more subtle. Validation is a priceless techniqueroughly, using an easy "grammar checker" for HTMLand you definitely should become familiar with it. The best return on your investment will come when you not only validate, but also check your HTML. You'll need two things:
- An HTML5 validator, such as Validator.nu
- An HTML5 checker such as HTML Lint
These tools quickly detect common spelling errors, missing characters, and other mistakes that plague many HTML sources. On a recent day when I used validator.nu to scan http://apple.com/, for instance, the validator detected four distinct and definite errors, including use of an obsolete frameborder attribute for iframe. However extensive your experience with HTML, and however disciplined your process for source creation, modern validation tools will likely improve your results.
Pick a Date
Do your end users ever need to schedule a future event, such as the expiration for an offer, or a target for a test run? Before HTML5, your choices for such a selection were simple textbox fill-ins with annoyingly complex validation (calendrical rules are complicated), or a more appealing graphical widget from any of several competing libraries.
Now your choice is much simpler:
<input type = "date" ...
This is HTML5's standard way of receiving user input for a calendar date. A sufficiently modern browser enforces that the only value that can result is a valid date. In the worst case, the input falls back to behave as an old-style textbox.
There's More! Further Structure for Your Forms
date is only one of 13 new input types that HTML5 makes available. You'll eventually want to learn and incorporate all of them. The availability of these new types allows you to concentrate on domain- and customer-specific concepts, while leveraging standard widgets for numeric values, search boxes, locale-savvy telephone numbers, color selection, and more.
Think for a moment how you'd ask your end user to pick a number between 1 and 50. You could construct a list box with 50 elements, but that would look awkward on most pages, and it would be clumsy to maintain as HTML. You could have users fill in a two-position text box and validate the result, with the overhead involved in programming validation. Or, with HTML5, you can write this:
<input type = "number" min = "1" max = "50" ...
With this option, you'll be certain that users can enter only proper whole numbers in the desired range. Even better than that, the user's view is of a standard widget that invites correct data entry.
Curious about which widgets work with which browsers? Learn the latest on this score with the Modernizr library, which efficiently detects and reports HTML5 feature support.
Join the Media Club
HTML5 is a large standard. Not only does the article you're reading right now not teach it all, but you probably will never learn all of it. That's okay; in fact, the most important aim of this article is not the five specific HTML5 items covered here, but the right attitude to have about HTML5. It's safe to learn little parts of HTML5 as they become useful to you, and then you can build on those parts to expand your HTML5 expertise.
Video is a part of HTML5 that illustrates this principle very well. As you'll see in a moment, you can learn one video construct right now that will pay off immediately for you. As your experience and comfort with it grows, you'll probably extend what you've learned "horizontally," into audio playback, and "vertically," where you'll acquire knowledge about different codecs and their roles, as well as the video configurations that HTML5 supports.
The place to start is with a simple tag:
<video src = "my_movie.webm"></video>
With this tag, you can embed your video on a web page, but not force end users into dependency on specific proprietary plug-ins such as Flash or QuickTime. That's a good thing! In fact, not only do most modern desktop browsers support video, but so do browsers available for most smartphones.
It's also far from the end. As you work with media formats, you'll learn that multimedia formatting is encumbered with technical tradeoffsand, even more, legal complexity. But it's right to begin simply by replacing the object, embed, or whatever you've been using, with video.
Search and Other Engines
While most of HTML5especially the graphical parts frequently publicized in strategic discussionsrequires JavaScript programming, at least one more important piece of HTML5 should be known to those operating purely at the tag level: HTML5 microdata. When we work with input and video and so on, we think in terms of what humans see, but web pages have another audience: search engines and other computer applications. Microdata can help you to get across the point of your web page to robotic readers.
In so-called search-engine optimization (SEO) circles, there's abundant speculation that the right microdata will move a page up in competitive search result rankings. While SEO is outside the scope of this introduction, it's likely that you'll be asked about microdata sometime. You'll need to learn enough about it to be able to answer with confidence that, yes, you can add HTML5 microdata markup.
Although HTML5 microdata operates mostly in the realm of tagged markup, it has even more depth and difficulty than video. Eventually you should read a couple of the fine tutorials that are available. For now, think of a specific concrete example: the "Contact Us" page on the last website you did. Here's how it might look with microdata decorations:
<div itemscope itemtype = "http://data-vocabulary.org/Organization"> <h3 itemprop = "name">The Organization</h3> This is a great organization. Here is what we say for people to read. <div itemprop = "address" itemscope itemtype = "http://data-vocabulary.org/Address"> <span itemprop = "street-address">135 Elm Street</span> ...
People will read this coding, including the physical address, and casually focus on the specific details of intereststreet address, telephone number, and so on, based on experience that teaches us "135 Elm Street" is more likely to be a street address than to be the name of the CEO. But itemprop explicitly identifies for search engines that this is a street-address, with the name of an Organization, and more. With HTML5 microdata, you clearly identify the tel and fax, and eliminate any possibility that search engines will mistake one for the other.
As with the other HTML5 elements in this introduction, you can start experimenting with microdata right away. However, the payoffs aren't as immediate: It's hard to be certain what a search engine "thinks" as it reads your pages, and browsers themselves are only beginning to interpret semantic markup.
You can set your own schedule for learning these various elements, as they're almost entirely independent of each other. In a world where so many readers are holding HTML5-enabled mobile handsets, however, surely now is the right time to start.