28 HTML5 Features, Tips, and Techniques you Must Know
basix

28 HTML5 Features, Tips, and Techniques you Must Know

Tutorial Details
  • Topic: HTML5
  • Estimated Difficulty: Basix
This entry is part 2 of 14 in the HTML5 and You Session
« PreviousNext »

Twice a month, we revisit some of our readers’ favorite posts from throughout the history of Nettuts+. This tutorial was first published in August, 2010.

This industry moves fast — really fast! If you’re not careful, you’ll be left in its dust. So, if you’re feeling a bit overwhelmed with the coming changes/updates in HTML5, use this as a primer of the things you must know.


1. New Doctype

Still using that pesky, impossible-to-memorize XHTML doctype?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

If so, why? Switch to the new HTML5 doctype. You’ll live longer — as Douglas Quaid might say.

<!DOCTYPE html>

In fact, did you know that it truthfully isn’t even really necessary for HTML5? However, it’s used for current, and older browsers that require a specified doctype. Browsers that do not understand this doctype will simply render the contained markup in standards mode. So, without worry, feel free to throw caution to the wind, and embrace the new HTML5 doctype.


2. The Figure Element

Consider the following mark-up for an image:

<img src="path/to/image" alt="About image" />
<p>Image of Mars. </p>

There unfortunately isn’t any easy or semantic way to associate the caption, wrapped in a paragraph tag, with the image element itself. HTML5 rectifies this, with the introduction of the <figure> element. When combined with the <figcaption> element, we can now semantically associate captions with their image counterparts.

<figure>
	<img src="path/to/image" alt="About image" />
	<figcaption>
		<p>This is an image of something interesting. </p>
	</figcaption>
</figure>

3. <small> Redefined

Not long ago, I utilized the <small> element to create subheadings that are closely related to the logo. It’s a useful presentational element; however, now, that would be an incorrect usage. The small element has been redefined, more appropriately, to refer to small print. Imagine a copyright statement in the footer of your site; according to the new HTML5 definition of this element; the <small> would be the correct wrapper for this information.

The small element now refers to “small print.”


4. No More Types for Scripts and Links

You possibly still add the type attribute to your link and script tags.

<link rel="stylesheet" href="path/to/stylesheet.css" type="text/css" />
<script type="text/javascript" src="path/to/script.js"></script>

This is no longer necessary. It’s implied that both of these tags refer to stylesheets and scripts, respectively. As such, we can remove the type attribute all together.

<link rel="stylesheet" href="path/to/stylesheet.css" />
<script src="path/to/script.js"></script>

5. To Quote or Not to Quote.

…That is the question. Remember, HTML5 is not XHTML. You don’t have to wrap your attributes in quotation marks if you don’t want to you. You don’t have to close your elements. With that said, there’s nothing wrong with doing so, if it makes you feel more comfortable. I find that this is true for myself.

<p class=myClass id=someId> Start the reactor. 

Make up your own mind on this one. If you prefer a more structured document, by all means, stick with the quotes.


6. Make your Content Editable

Content Editable

The new browsers have a nifty new attribute that can be applied to elements, called contenteditable. As the name implies, this allows the user to edit any of the text contained within the element, including its children. There are a variety of uses for something like this, including an app as simple as a to-do list, which also takes advantage of local storage.

<!DOCTYPE html>

<html lang="en">
<head>
	<meta charset="utf-8">
	<title>untitled</title>
</head>
<body>
	<h2> To-Do List </h2>
     <ul contenteditable="true">
		<li> Break mechanical cab driver. </li>
		<li> Drive to abandoned factory
		<li> Watch video of self </li>
	 </ul>
</body>
</html>

Or, as we learned in the previous tip, we could write it as:

<ul contenteditable=true>

7. Email Inputs

If we apply a type of “email” to form inputs, we can instruct the browser to only allow strings that conform to a valid email address structure. That’s right; built-in form validation will soon be here! We can’t 100% rely on this just yet, for obvious reasons. In older browsers that do not understand this “email” type, they’ll simply fall back to a regular textbox.

<!DOCTYPE html>

<html lang="en">
<head>
	<meta charset="utf-8">
	<title>untitled</title>
</head>
<body>
	<form action="" method="get">
		<label for="email">Email:</label>
		<input id="email" name="email" type="email" />

		<button type="submit"> Submit Form </button>
	</form>
</body>
</html>
Email Validation

At this time, we cannot depend on browser validation. A server/client side solution must still be implemented.

It should also be noted that all the current browsers are a bit wonky when it comes to what elements and attributes they do and don’t support. For example, Opera seems to support email validation, just as long as the name attribute is specified. However, it does not support the placeholder attribute, which we’ll learn about in the next tip. Bottom line, don’t depend on this form of validation just yet…but you can still use it!


8. Placeholders

Before, we had to utilize a bit of JavaScript to create placeholders for textboxes. Sure, you can initially set the value attribute how you see fit, but, as soon as the user deletes that text and clicks away, the input will be left blank again. The placeholder attribute remedies this.

<input name="email" type="email" placeholder="doug@givethesepeopleair.com" />

Again, support is shady at best across browsers, however, this will continue to improve with every new release. Besides, if the browser, like Firefox and Opera, don’t currently support the placeholder attribute, no harm done.

Validation

9. Local Storage

Thanks to local storage (not officially HTML5, but grouped in for convenience’s sake), we can make advanced browsers “remember” what we type, even after the browser is closed or is refreshed.

“localStorage sets fields on the domain. Even when you close the browser, reopen it, and go back to the site, it remembers all fields in localStorage.”
-QuirksBlog

While obviously not supported across all browsers, we can expect this method to work, most notably, in Internet Explorer 8, Safari 4, and Firefox 3.5. Note that, to compensate for older browsers that won’t recognize local storage, you should first test to determine whether window.localStorage exists.

Support matrix

via http://www.findmebyip.com/litmus/

10. The Semantic Header and Footer

Gone are the days of:

<div id="header">
	...
</div>

<div id="footer">
	...
</div>

Divs, by nature, have no semantic structure — even after an id is applied. Now, with HTML5, we have access to the <header> and <footer> elements. The mark-up above can now be replaced with:

<header>
	...
</header>

<footer>
	...
</footer>

It’s fully appropriate to have multiple headers and footers in your projects.

Try not to confuse these elements with the “header” and “footer” of your website. They simply refer to their container. As such, it makes sense to place, for example, meta information at the bottom of a blog post within the footer element. The same holds true for the header.


11. More HTML5 Form Features

Learn about more helpful HTML5 form features in this quick video tip.


12. Internet Explorer and HTML5

Unfortunately, that dang Internet Explorer requires a bit of wrangling in order to understand the new HTML5 elements.

All elements, by default, have a display of inline.

In order to ensure that the new HTML5 elements render correctly as block level elements, it’s necessary at this time to style them as such.

header, footer, article, section, nav, menu, hgroup { 
   display: block;
}

Unfortunately, Internet Explorer will still ignore these stylings, because it has no clue what, as an example, the header element even is. Luckily, there is an easy fix:

document.createElement("article");
document.createElement("footer");
document.createElement("header");
document.createElement("hgroup");
document.createElement("nav");
document.createElement("menu");

Strangely enough, this code seems to trigger Internet Explorer. To simply this process for each new application, Remy Sharp created a script, commonly referred to as the HTML5 shiv. This script also fixes some printing issues as well.

<!--[if IE]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

13. hgroup

Imagine that, in my site’s header, I had the name of my site, immediately followed by a subheading. While we can use an <h1> and <h2> tag, respectively, to create the mark-up, there still wasn’t, as of HTML4, an easy way to semantically illustrate the relationship between the two. Additionally, the use of an h2 tag presents more problems, in terms of hierarchy, when it comes to displaying other headings on the page. By using the hgroup element, we can group these headings together, without affecting the flow of the document’s outline.

<header>
	<hgroup>
		<h1> Recall Fan Page </h1>
		<h2> Only for people who want the memory of a lifetime. </h2>
	</hgroup>
</header>


14. Required Attribute

Forms allow for a new required attribute, which specifies, naturally, whether a particular input is required. Dependent upon your coding preference, you can declare this attribute in one of two ways:

<input type="text" name="someInput" required>

Or, with a more structured approach.

<input type="text" name="someInput" required="required">

Either method will do. With this code, and within browsers that support this attribute, a form cannot be submitted if that “someInput” input is blank. Here’s a quick example; we’ll also add the placeholder attribute as well, as there’s no reason not to.

<form method="post" action="">
	<label for="someInput"> Your Name: </label>
	<input type="text" id="someInput" name="someInput" placeholder="Douglas Quaid" required>
	<button type="submit">Go</button>
</form>
Required and Placeholder Attributes

If the input is left blank, and the form is submitted, the textbox will be highlighted.


15. Autofocus Attribute

Again, HTML5 removes the need for JavaScript solutions. If a particular input should be “selected,” or focused, by default, we can now utilize the autofocus attribute.

<input type="text" name="someInput" placeholder="Douglas Quaid" required autofocus>

Interestingly enough, while I personally tend to prefer a more XHTML approach (using quotation marks, etc.), writing "autofocus=autofocus" feels odd. As such, we’ll stick with the single keyword approach.


16. Audio Support

No longer do we have to rely upon third party plugins in order to render audio. HTML5 now offers the <audio> element. Well, at least, ultimately, we won’t have to worry about these plugins. For the time being, only the most recent of browsers offer support for HTML5 audio. At this time, it’s still a good practice to offer some form of backward compatibility.

<audio autoplay="autoplay" controls="controls">
	<source src="file.ogg" />
	<source src="file.mp3" />	
	Download this file.
</audio>

Mozilla and Webkit don’t fully get along just yet, when it comes to the audio format. Firefox will want to see an .ogg file, while Webkit browsers will work just fine with the common .mp3 extension. This means that, at least for now, you should create two versions of the audio.

When Safari loads the page, it won’t recognize that .ogg format, and will skip it and move on to the mp3 version, accordingly. Please note that IE, per usual, doesn’t support this, and Opera 10 and lower can only work with .wav files.


17. Video Support

Much like the <audio> element, we also, of course, have HTML5 video as well in the new browsers! In fact, just recently, YouTube announced a new HTML5 video embed for their videos, for browsers which support it. Unfortunately, again, because the HTML5 spec doesn’t specify a specific codec for video, it’s left to the browsers to decide. While Safari, and Internet Explorer 9 can be expected to support video in the H.264 format (which Flash players can play), Firefox and Opera are sticking with the open source Theora and Vorbis formats. As such, when displaying HTML5 video, you must offer both formats.

<video controls preload>
	<source src="cohagenPhoneCall.ogv" type="video/ogg; codecs='vorbis, theora'" />
	<source src="cohagenPhoneCall.mp4" type="video/mp4; 'codecs='avc1.42E01E, mp4a.40.2'" />
	<p> Your browser is old. <a href="cohagenPhoneCall.mp4">Download this video instead.</a> </p>
</video>

Chrome can correctly display video that is encoded in both the “ogg” and “mp4″ formats.

There are a few things worth noting here.

  1. We aren’t technically required to set the type attribute; however, if we don’t, the browser has to figure out the type itself. Save some bandwidth, and declare it yourself.
  2. Not all browsers understand HTML5 video. Below the source elements, we can either offer a download link, or embed a Flash version of the video instead. It’s up to you.
  3. The controls and preload attributes will be discussed in the next two tips.

18. Preload Videos

The preload attribute does exactly what you’d guess. Though, with that said, you should first decide whether or not you want the browser to preload the video. Is it necessary? Perhaps, if the visitor accesses a page, which is specifically made to display a video, you should definitely preload the video, and save the visitor a bit of waiting time. Videos can be preloaded by setting preload="preload", or by simply adding preload. I prefer the latter solution; it’s a bit less redundant.

<video preload>

19. Display Controls

If you’re working along with each of these tips and techniques, you might have noticed that, with the code above, the video above appears to be only an image, without any controls. To render these play controls, we must specify the controls attribute within the video element.

<video preload controls>
Options

Please note that each browser renders its player differently from one another.


20. Regular Expressions

How often have you found yourself writing some quickie regular expression to verify a particular textbox. Thanks to the new pattern attribute, we can insert a regular expression directly into our markup.

<form action="" method="post">
	<label for="username">Create a Username: </label>
   	<input type="text" 
	   name="username" 
	   id="username"
	   placeholder="4 <> 10"
	   pattern="[A-Za-z]{4,10}"
	   autofocus
	   required>
	<button type="submit">Go </button>
</form>

If you’re moderately familiar with regular expressions, you’ll be aware that this pattern: [A-Za-z]{4,10} accepts only upper and lowercase letters. This string must also have a minimum of four characters, and a maximum of ten.

Notice that we’re beginning to combine all of these new awesome attributes!

If regular expressions are foreign to you, refer here.


21. Detect Support for Attributes

What good are these attributes if we have no way of determining whether the browser recognizes them? Well, good point; but there are several ways to figure this out. We’ll discuss two. The first option is to utilize the excellent Modernizr library. Alternatively, we can create and dissect these elements to determine what the browsers are capable of. For instance, in our previous example, if we want to determine if the browser can implement the pattern attribute, we could add a bit of JavaScript to our page:

alert( 'pattern' in document.createElement('input') ) // boolean;

In fact, this is a popular method of determining browser compatibility. The jQuery library utilizes this trick. Above, we’re creating a new input element, and determining whether the pattern attribute is recognized within. If it is, the browser supports this functionality. Otherwise, it of course does not.

<script>
if (!'pattern' in document.createElement('input') ) {
	// do client/server side validation
}
</script>

Keep in mind that this relies on JavaScript!


22. Mark Element

Think of the <mark> element as a highlighter. A string wrapped within this tag should be relevant to the current actions of the user. For example, if I searched for “Open your Mind” on some blog, I could then utilize some JavaScript to wrap each occurrence of this string within <mark> tags.

<h3> Search Results </h3>
<p> They were interrupted, just after Quato said, <mark>"Open your Mind"</mark>. </p>


23. When to Use a <div>

Some of us initially questioned when we should use plain-ole divs. Now that we have access to headers, articles, sections, and footers, is there ever a time to use a…div? Absolutely.

Divs should be utilized when there’s no better element for the job.

For example, if you find that you need to wrap a block of code within a wrapper element specifically for the purpose of positioning the content, a <div> makes perfect sense. However, if you’re instead wrapping a new blog post, or, perhaps, a list of links in your footer, consider using the <article> and <nav> elements, respectively. They’re more semantic.


24. What to Immediately Begin Using

With all this talk about HTML5 not being complete until 2022, many people disregard it entirely – which is a big mistake. In fact, there are a handful of HTML5 features that we can use in all our projects right now! Simpler, cleaner code is always a good thing. In today’s video quick tip, I’ll show you a handful of options.


25. What is Not HTML5

People can be forgiven for assuming that awesome JavaScript-less transitions are grouped into the all-encompassing HTML5. Hey — even Apple has inadvertently promoted this idea. For non-developers, who cares; it’s an easy way to refer to modern web standards. However, for us, though it may just be semantics, it’s important to understand exactly what is not HTML5.

  1. SVG: Not HTML5. It’s at least five years old.
  2. CSS3: Not HTML5. It’s…CSS.
  3. Geolocation: Not HTML5.
  4. Client Storage: Not HTML5. It was at one point, but was removed from the spec, due to the fact that many worried that it, as a whole, was becoming too complicated. It now has its own specification.
  5. Web Sockets: Not HTML5. Again, was exported to its own specification.

Regardless of how much distinction you require, all of these technologies can be grouped into the modern web stack. In fact, many of these branched specifications are still managed by the same people.


26. The Data Attribute

We now officially have support for custom attributes within all HTML elements. While, before, we could still get away with things like:

<h1 id=someId customAttribute=value> Thank you, Tony. </h1>

…the validators would kick up a fuss! But now, as long as we preface our custom attribute with “data,” we can officially use this method. If you’ve ever found yourself attaching important data to something like a class attribute, probably for JavaScript usage, this will come as a big help!

HTML Snippet

<div id="myDiv" data-custom-attr="My Value"> Bla Bla </div>

Retrieve Value of the Custom Attribute

var theDiv = document.getElementById('myDiv');
var attr = theDiv.getAttribute('data-custom-attr'); 
alert(attr); // My Val

It can also even be used in your CSS, like for this silly and lame CSS text changing example.

<!DOCTYPE html>

<html lang="en">
<head>
   <meta charset="utf-8">
   <title>Sort of Lame CSS Text Changing</title>
<style>

h1 { position: relative; }
h1:hover { color: transparent; }

h1:hover:after {
	content: attr(data-hover-response);
	color: black;
	position: absolute;
	left: 0;

}
</style>
</head>
<body>

<h1 data-hover-response="I Said Don't Touch Me!"> Don't Touch Me  </h1>

</body>
</html>

You can view a demo of the effect above on JSBIN.


27. The Output Element

As you probably have guessed, the output element is used to display some sort of calculation. For example, if you’d like to display the coordinates of a mouse position, or the sum of a series of numbers, this data should be inserted into the output element.

As a simple example, let’s insert the sum of two numbers into an empty output with JavaScript, when a submit button is pressed.

<form action="" method="get">
	<p> 
		10 + 5 = <output name="sum"></output> 
	</p>
	<button type="submit"> Calculate </button>
</form>

<script>
(function() {
	var f = document.forms[0];
	
	if ( typeof f['sum'] !== 'undefined' ) {
		f.addEventListener('submit', function(e) {
			f['sum'].value = 15;
			e.preventDefault();
		}, false);
	}
	else { alert('Your browser is not ready yet.'); }
})();
</script>

Try it out for yourself.

Please note that support for the output element is still a bit wonky. At the time of this writing, I was only able to get Opera to play nice. This is reflected in the code above. If the browser does not recognize the element, the browser will simply alert a notice informing you of as much. Otherwise, it finds the output with a name of “sum,” and sets its value to 15, accordingly, after the form has been submitted.

Output element

This element can also receive a for attribute, which reflects the name of the element that the output relates to, similar to the way that a label works.


28. Create Sliders with the Range Input

HTML5 introduces the new range type of input.

<input type="range">

Most notably, it can receive min, max, step, and value attributes, among others. Though only Opera seems to support this type of input right now fully, it’ll be fantastic when we can actually use this!

For a quick demonstration, let’s build a gauge that will allow users to decide how awesome “Total Recall” is. We won’t build a real-world polling solution, but we’ll review how it could be done quite easily.

Step 1: Mark-up

First, we create our mark-up.

<form method="post">
	<h1> Total Recall Awesomness Gauge </h1>
	<input type="range" name="range" min="0" max="10" step="1" value="">
	<output name="result">  </output>
</form>
Unstyled range input

Notice that, in addition to setting min and max values, we can always specify what the step for each transition will be. If the step is set to 1, there will then be 10 values to choose. We also take advantage of the new output element that we learned about in the previous tip.

Step 2: CSS

Next, we’ll style it just a bit. We’ll also utilize :before and :after to inform the user what our specified min and max values are. Thanks so much to Remy and Bruce for teaching me this trick, via “Introducing HTML5.”

body {
	font-family: 'Myriad-Pro', 'myriad', helvetica, arial, sans-serif;
	text-align: center;
}
input { font-size: 14px; font-weight: bold;  }

input[type=range]:before { content: attr(min); padding-right: 5px; }
input[type=range]:after { content: attr(max); padding-left: 5px;}

output { 
	display: block;
	font-size: 5.5em;
	font-weight: bold;
}

Above, we create content before and after the range input, and make their values equal to the min and max values, respectively.

Styled Range

Step 3: The JavaScript

Lastly, we:

  • Determine if the current browser knows what the range input is. If not, we alert the user that the demo won’t work.
  • Update the output element dynamically, as the user moves the slider.
  • Listen for when the user mouses off the slider, grab the value, and save it to local storage.
  • Then, the next time the user refreshes the page, the range and output will automatically be set to what they last selected.
(function() {
	var f = document.forms[0],
		range = f['range'],
		result = f['result'],
		cachedRangeValue = localStorage.rangeValue ? localStorage.rangeValue : 5; 
	
	// Determine if browser is one of the cool kids that 
	// recognizes the range input.
	var o = document.createElement('input');
	o.type = 'range';
	if ( o.type === 'text' ) alert('Sorry. Your browser is not cool enough yet. Try the latest Opera.');

	// Set initial values of the input and ouput elements to
	// either what's stored locally, or the number 5.
	range.value = cachedRangeValue;
	result.value = cachedRangeValue;

	// When the user makes a selection, update local storage.
	range.addEventListener("mouseup", function() {
		alert("The selected value was " + range.value + ". I am using local storage to remember the value. Refresh and check on a modern browser.");
		localStorage ? (localStorage.rangeValue = range.value) : alert("Save data to database or something instead.");
	}, false);
	
	// Display chosen value when sliding. 
	range.addEventListener("change", function() {
		result.value = range.value;
	}, false);
	
})();
Styled Range with JS

Ready for the real world? Probably not yet; but it’s still fun to play with and prep for!

Download the source code, and try it out for yourself. But use Opera.


Thanks for reading! We’ve covered a lot, but have still only scratched the surface of what’s possible with HTML5. I hope this served as a helpful primer!

Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://www.jeffrey-way.com Jeffrey Way
    Author

    And the movie referenced through out these tips is….?

    • http://blog.verysofisticated.com/ Matt

      Total Recall?

      • http://www.jeffrey-way.com Jeffrey Way
        Author

        Yep!

      • Jason Andreoni

        Yup, Total Recall. I caught that immediately. =)

      • Danilo

        I don’t get it. How’s that?

      • Jason Andreoni

        Danilo, in Step 8, Jeffrey uses “doug@givethesepeopleair.com” as the example email address.

        Doug was Schwarzenegger’s name in the Total Recall, and he spoke the very-quotable line “Give these people air!” in that classic Schwarzenegger accent.

  • http://twitter.com/mattle Matthew Callier

    Great compilation of information. For me, the challenge of HTML5 is understanding exactly when each of the new semantic tags is appropriate. But I’m still a big fan of these new additions.

    Couple minor typos. In the first example, your HTML5 doctype is missing the exclamation mark. In the second example, became <.

    • http://twitter.com/mattle Matthew Callier

      Oops, comment filter mangled second example. The image tag has one too many angled brackets :)

      • http://twitter.com/mattle Matthew Callier

        I would really like to be able to edit or delete my comments here (perhaps for a minute or so after posting). It seems that the issue with the img tag in the second example is now a missing “i”.

  • http://www.sladewebsolutions.com Thomas Slade

    Awesome article Jeff!

  • David

    Hi Jeffrey,

    Do you mind to correct the “< ” on the tips #2? :)

    -David

    • http://www.jeffrey-way.com Jeffrey Way
      Author

      Done.

  • http://www.ultramegatech.com/ Steve Guidetti

    Nice introduction to HTML5 :)

    Here’s a pretty handy reference for testing for all these features with JavaScript: http://diveintohtml5.org/everything.html

  • leo rapirap

    maybe i should soon start using html5 on my projects. thanks Jeff!

  • http://www.starkjr.com Thomas Stark jr.

    Awesome article. I was looking for some kind of “xx html 5 features” today and after netttuts+ posted a tweet about it, I immediately went here and read the whole article from its first to the last point. Very nice!

  • http://www.ink-sketch.com/ InkSketch

    Thanks. This is very cool. It’s always been easier for me to swallow a book to get the info embedded into my brain properly and I just haven’t gone out to purchase one yet. This answers a lot of the questions that I had. I can’t wait until all of the browsers are in the loop.
    Thanks again for sharing.

  • http://www.efdezigns.com Eric

    Great overview! For the type attributes under number 4… would we still need to include the type=”text/css” in a conditional IE comment or is it ok to leave it out of those as well?

    • http://johan.notitia.nl/ Johan de Jong

      At this point IE has no support for HTML5 what so ever. As pointed out at #12 you need to define the new elements manually and techniques like removing the type from the style and script elements will cause problems.

      I’m not sure about removing the type at the link element, since link can be anything; css, rss, favicons, etc. So I don’t think a browser will be able to auto-asign the type by itself.

      Another “new” thing whih you can use in HTML5 is instead of , although, again, it’s not supported by older browsers like IE.

      • http://johan.notitia.nl/ Johan de Jong

        ROFL… the HTML examples I gave where removed…

        the example I wanted to give was:

        meta charset=”utf-8″

        instead of

        meta content=”text/html; charset=UTF-8″ http-equiv=”Content-Type”

      • http://paulirish.com Paul Irish

        #1-6 will all work in IE6-8 just peachy. The new elements require the use of the html5shim or Modernizr and you’re all good.

        link, style, and script tags do not need the type attribute. Browsers didn’t use them before, they’re only for validation. the rel attribute does the job of pointing out what sort of link tag it is… that one is still required.

        Also the shorter meta charset works perfectly fine even in IE.

        I know it’s a leap of faith to buy into that, but.. it’s true. :)
        Same with crazy things like not closing your LI or TD tags. Works fine everywhere.

    • Robert

      From what I have seen and used, both Internet Explorer 7 and 8 don’t mind if you leave out the type attribute in the or tags, so you shouldn’t have to use conditional comments for that.

      • Robert

        should have read *don’t mind if you leave out the type attribute in the link and script tags.*

      • http://www.efdezigns.com Eric

        Thanks for the responses. What I meant by that was when you need to add a stylesheet or script just for IE6 for example.. would it be ok to still leave out the type attributes in the conditional statements since it is only targeting IE? I guess it wouldn’t make a difference if it works fine with the other ones.

  • http://digitalformula.net/ Chris

    One of, if not the best intro to the most useful HTML5 elements yet.

    Thanks, Jeff. :)

  • K Arun Mariappan

    Nice Collection of Tips.. Thanks…

  • http://wanz.im 丸子

    contenteditable is an ie5.5+ supported attribute..

  • http://luongdiennhan13.blogspot.com/ Luong Dien Nhan

    Very good introduction about HTML5. Do you have introduction about WebSocket?

  • JonQ

    Awesome posts I’m really liking the prospect of using html5. Love your posts! I became a premium user because of it!

    Was just wondering you knew of a good community where a beginner could get some affirmation of whether they are doing everything right? Kinda like a teacher checking for any errors or catching bad habits.

  • http://www.hastishah.com Hastimal Shah

    Very good explanation. i really like this even good tips.
    Waiting for more in HTML 5 and CSS3
    Thanks

  • http://imknight.net Knight

    I wonder is css part of the HTML 5 or not ? it does included in http://slides.html5rocks.com/#slide4 , but not on this post.

    • http://johan.notitia.nl/ Johan de Jong

      No, HTML has nothing to do with CSS.

      HTML (HyperText Markup Language) is a markup language, while CSS (Cascading Style Sheets) is a styling language.

  • http://www.ifadey.com Fawad Hassan

    Wao!
    Very nice summary of current HTML5 features :)

  • Marcin

    An excellent and well-researched roundup. I’ve read it from top to bottom and I’m going to bookmark it for future reference – I guess it’s time to start using these things, at least with proper fallback for lesser browsers ;-)

  • http://develop-d-web.blogspot.com/ Fred Timajo

    Isn’t the functionality of autofocus already existed? Remember tabindex=”1″?

    btw: great article!

    • Robert

      Using tabindex=’1′ isn’t quite the same thing as autofocus. When a textbox as a tabindex of 1, then that textbox won’t receive focus until the user actually presses the tab key once the page is loaded. However, if a textbox has the autofocus attribute, that textbox will receive focus as soon as the page is done loading without the user having to do anything (no tab, no clicking, etc).

      • http://develop-d-web.blogspot.com/ Fred Timajo

        Thanks for that detailed explanation Robert.

  • http://www.brianbatesd.com Brian

    Awesome overview. Haven’t spent much time with HTML 5 but have been following it here and there.

  • sunny

    Hey Jeffrey, I don’t know if this is a right question . Does HTML5 works on localhost? using xampp on windows?
    Because I’m trying to run different demos of HTML5 and it doesn’t work =(

    • http://johan.notitia.nl/ Johan de Jong

      HTML5 has nothing to do with the server it runs at, it’s only depends on your browser. eg IE doesn’t support HTML5, while Firefox, Safari, Chrome and Opera do, but not fully yet.

      • sunny

        Then, why is it simple HTML file not working on Firefox 3.6 and Chrome 5.0 ? :S

  • http://www.stefanogiordano.it Stefano

    Nice walk-through, Jeffrey! :) maybe it would be a good idea to start a series on HTML5 and relative fallback solutions for “old school” browsers.

  • ashnur

    #5. To Quote or Not to Quote.

    i never understood this. why should this make anything better. we are actually losing functionality if we drop the quotes, i.e. when you want to add multiple classes for the same element.

    • http://paulirish.com Paul Irish

      Yup. there’s a lot of times when not quoting reduces your capabilities.. like multiple classes.
      But plenty of other cases where you don’t need them. You can mix and match if you want.. Just like mixing double quotes and single quotes is fine.

      It’s all very personal preference.. The unquoted style looks pretty good to me.. plus I can save an extra 1kb or so of markup per page.

  • Jeroen

    When do you think we can safely start using this?
    I still detect IE6 users in my google analytics results…

    one year? two?

    • http://www.xoen.org Aldo “xoen” Giambelluca

      IMHO it’s better stop supporting IE6.

      I know it’s not possible for some targets but we should stop *trying* to be compatible with IE6.

  • http://nicolahibbert.com Nikki

    Bit of a caveat with number 21: if you try to detect support for each of the new input type values (date-time, search, etc) in Webkit browsers, the test will pass whether the browser supports that particular input type or not. Mike Taylor did some workarounds for this in the Modernizr library, check out the source if you’re interested.

  • http://www.dangermoose.co.uk flashmac

    Surprised the new simple ‘range’ attribute was omitted, but I guess the list could have gone on forever. Thanks for the round up. World has gone HTML5 crazy.

    For those wanting abit more. Sitepoint are offering a 10 day HTML5 course for $10 (bargain). http://courses.sitepoint.com/html5-live

  • http://mathiasbynens.be/ Mathias Bynens

    “5. To Quote or Not to Quote.” — This is not new in HTML5 at all; it’s how HTML has always worked.

    “25. What is not HTML5″ — Sure, SVG is not part of HTML5, but you should probably note that HTML5 now allows inline SVG, which wasn’t allowed before.

  • AndyDandy

    Any advice on how to upgrade to HTML5 an already existing website?
    If I just change the doctype and add some new tag here and there, the rest of the markup will be simply wrong … And I would not want to rewrite the three years old site from scratch.

  • http://aniri.ro Irina

    Nice tips! Thank you for the list!

  • http://abhilashatyagi.blogspot.com/ Abhilasha Tyagi

    Thank u so much for the tips..they r very helpful, though not very useful for the still old browsers that most of us use.
    Hope v start using them soon as they r clean

    Regards
    Abhilasha Tyagi

  • Patrick

    I’ll never use HTML5 if not all browsers support this in exactly the same way. And, we all know, that IE won’t never support this within the next 3 to 5 years like the alternative browsers will. And we know, that there are thousands of DAUs, who use this browser. So, the HTML5 hype is absolutely not understandable.

    But, there are some good things in this specifications. Will make some things easier. But, it’s not perfect.

    • http://jelmerdemaat.nl Jelmer

      That is not really flexible thinking. You’d still be waiting today for every browser to support CSS 2.1 completely. If we are all going to wait, HTML5 will never be used.

      • Patrick

        sure you can use HTML5. But i think it’s really not ready for productional use. Why don’t wait until the specifications are fixed? At this time you have to check if the browser supports html5 if you want that your site works as expected. If it doesn’t support html5, you need to use a fallback solution. You probably have a lot more work to do.

        At this time it’s like batfan says. It’s better using javascript based solutions for all HTML5-features than true html5 features, because you can more easily say “please activate javascript to use this site” than “please use a fully functional html5 browser”.

      • http://jelmerdemaat.nl Jelmer

        I agree with you on the Javascript solution things, I won’t be using too many features I need to build a Javascript fallback for. But I will use HTML5 features that are supported by major browsers, things that don’t necessarily need to have a fallback, or things that just have a simple fallback solution.
        I just can’t wait and use nothing of it until everything is done and specifications are fixed. Plus they might hurry up a little when everybody starts using it already. ;)

      • http://www.xoen.org Aldo “xoen” Giambelluca

        > If we are all going to wait, HTML5 will never be used.

        Exactly.

        @Patrick
        > you can more easily say “please activate javascript to use this site” than
        > “please use a fully functional html5 browser”.

        Yes, JS is safer at the moment, but I think “please use a fully functional html5 browser” should be used more often.

        I guess people using IE don’t see the difference if they switch browser because they aren’t geek, they just use these browser because they found it installed. Switch browser is easy [1], and a more than a browser can be installed on a computer, so we should just use standards [2] and stop trying to be compatible to everything, also old stuff with little market share, just because people are too lazy.

        [1] Of course there are some intranet application that needs IE6 to run.
        [2] …but HTML5 is not yet a standard, am I wrong?

    • Batfan

      I partially agree with Patrick.

      While I find this article very informative, I’m going to be holding off on HTML5 for now. Perhaps when IE9 gets a little more widely used, I will begin implementing it.

      It just seems like a lot of extra markup and work to make use of these features for browsers that support them and put in place workarounds for browsers that don’t. For now I prefer to use JQuery to do most of this. It takes less time and just works, in nearly all browsers.

  • http://twitter.com/Lateralaus Phillip

    Brilliant article. Very informative and I enjoyed reading it.

  • http://www.crearedesign.co.uk Steve Maggs

    Articles like this definitely help to reassure me that I should start building sites using HTML5 now. I think that to be able to hit the ground running when all browsers (and the majority of users) have full HTML5 support I need to start learning the nuances of it now.

    Taking it in bit by but like this is ideal.

  • Al

    NIce article, very supportive for getting to know HTML 5

  • http://vlhome.com virdfel

    good article!
    and., recommend the book HTML5, basic and pro,, plz)

  • http://www.jordanwalker.net Jordan Walker

    Thanks for the excellent round up, it will be nice when the w3c finalizes this standard.

  • Nate

    Great article, and love the Total Recall references

    “Be home in time for Corn Flakes”

  • Mohamed Zahran

    Thanks Jeff, Wonderful as usual ;)

  • http://www.uk-severe-weather.co.uk tristar

    Really useful HTML5 insight there. Looks like I might be spending time learning these new features =)

  • http://www.aediscreative.com Christopher

    2022… seriously? ugh.

    • http://paulirish.com Paul Irish

      2022 refers to the date when two fully compatible implementations are in the wild. FWIW that hasnt happened for CSS 2.1 or HTML4 or XHTML1.1 … so….

      it’s kind of a useless thing to focus on. :)

  • http://chrisdasie.com Chris Da Sie

    A great list of elements to help everyone get started with HTML5. It really is changing the web.

  • http://www.napolitopia.com Sam Napolitano

    Jeffrey, Great article, but I am not sure why anyone would EVER want to not put quotes around their attribute values (#5). Just for the sake of at least ‘some’ backwards compatibility you would need to use them, not to mention it makes code much easier to read… I would like to hear other peoples thoughts on this. I can’t be the only one who thinks that is just bad coding practice.

    I love some of the other great features you outlined, I think ‘figure’ and the changes to the ‘small’ tag are 2 things no one has really brushed on yet that are going to be tremendously different, especially when it comes to SEO.

    • http://yuraji.com Yura Linnyk

      Back in the old days like ten years ago you could often see attribute values without quotes, it was definitely not required until xhtml appeared. I remember some web designers seriously discussed how they were saving bandwidth by omitting quotes that weren’t really required :)

      But then, even if it works without quotes, you can’t attach more than one class to a tag without them!
      And it definitely sounds like a bad practice to me.

  • http://abhijeets06.posterous.com/ Abhijeet

    Wow thanks

  • http://freecss.info CSS Tutorials

    Great runthrough. I previously wasn’t too interested in any new features but some of these are actually useful.

  • http://www.bauglir.com Bronislav Klucka

    Nice,
    just a few points:
    1/ About doctype and quotes: HTML5 defines a language that can be written in 2 ways (serializations) HTML (which is a brand new way, not SGML application, as previous versions were) and XHTML (XML application), the serialization is defined by passed content type. So if one is using XHTML serialization, one have to obey XML rules (doctype, quotes, either void tags or closing every tag).
    Some informations can be found at http://wiki.whatwg.org/wiki/HTML_vs._XHTML

    2/ 2022
    Do not be affraid of this date, do not thing “what in the hell might be changed if I start to use it now, what do they need another 12 year for”. There are simple W3C rules applied: There must be 2 independent implementations of entire draft for it to become Recommendation. And because of the extent of the specification, it will take a lot of time. But the important thing for developers is Candidate Recommendation which should be the final draft waiting for implementators to be implemented. And this is expected in 2012, after this status is achieved, there should be no more changes in the spec (maybe minor due to vendors implementations issues). The most part of current version is in “last call” state, which represents “we are done here and if you cannot find some serious problems here, we are done”
    So do not be affraid to use it.
    BTW CSS2.1 is here for 10 years, everybody is using it and it is still not Recommendation, because there are no 2 independent full implementations :)

  • mario

    //That is the question. Remember, HTML5 is not XHTML. You don’t have to wrap your attributes in quotation marks if you don’t want to you. You don’t have to close your elements. With that said, there’s nothing wrong with doing so, if it makes you feel more comfortable. I find that this is true for myself.//

    i just can understend this —- during ten years we learn about the problem to develop in this way and now you say that this its optional

    • http://www.napolitopia.com Sam Napolitano

      I fully agree, we have been fighting phantom quotes and unclosed entity tags for years. I can’t fathom a world where this is even considered an option.

  • http://prop-14.com Randy

    From #5
    “You don’t have to close your elements.”
    This ones worries me. So the CSS will know that when you start an h4 it will not inherit a previous h5 styling for example that has no closing tag?

    From #20
    “we can insert a regular expression directly into our markup”
    I thought the trend was to keep “functionality” code in external files while keeping the documents clean with only content? (Admitted, this is only a small amount of code.)

  • http://blog.davidsteinsland.net David Steinsland

    The “required” attribute isn’t HTML5. I’ve been using it for years… Since the title is “Techniques you _must_ know”, I really think you’ve forgotten alot of the other HTML5 specs that are coming. Nice run-up though.

  • http://connorcrosby.me Connor Crosby

    Awesome article! I had no idea about some of those features, thanks.

  • http://mileonemedia.com Joe

    ugh. I know it doesn’t matter if you close elements, and I know you don’t *need* to put quotes around attributes, but do we really want to to back to 1997? We are, HTML developers really THAT lazy?

    • http://mileonemedia.com Joe

      That last line should read: Are we HTML developers really that lazy.