I just spent some time with HTML5. To be more specific, I just rewrote my favorite Rails app in HTML5. It was like a dream! It took me back to a simpler time… When you can reduce this:
you just feel lighter. I’ve been working in XHTML since it became the
next big thing. Getting used to all those
<br />s took some time, but I
eventually got used to it. Getting used to a
<tbody> for every
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> for
<head> was tough, but I persevered. I didn’t just survive; I
thrived! Yes! More rules! More structure! See how Vim indents this
automatically? That’s how you know it’s right! All is right with The Web.
Or so I thought…
Enter HTML5. I don’t need a
/ for that
<img>? Cool. I don’t need a
<p>? I don’t need quotes around my attributes? Now I know you’re
messing with me. What? I don’t even need
just see about this!
So, being a devout and dutiful developer, I paste it into the W3C Validator, and to my astonishment, it validates! It validates! I know! I was shocked, too! It doesn’t just look good in the browser because the browser is making its best guess in quirks mode. It looks good because I have written valid, well-formed code! And it’s not just well-formed; it’s sexy.
Then why did I ever move to XHTML? If I wanted to write web pages the free and easy way, I could have been writing web pages in HTML 4 all this time, right?
I guess so.
The aspects of XHTML that most appealed to me was that its rigid structure
required that documents be well-formed, and that the removal of presentation
<font> encouraged writing semantic pages. Then
there’s serialization and mashability. If the document is XHTML, it’s XML, and
you can import it with Ajax and parse the DOM tree programmatically.
But now I realize that XHTML is not necessary to achieve these things. HTML5
does a better job of encouraging semantic web development with elements like
<aside>. You can still use DOM rules to parse
HTML5. Most of all, while XHTML ensures well-formed documents, there’s no
reason that you can’t just hold yourself to a higher standard and write good
So I’m making the switch. And it’s easy! Most of my XHTML 1.0 Strict is valid HTML5. All I really had to do to convert my Rails app was change the DOCTYPE from
The Rails generated code is still XHTML compliant, but it is also valid HTML5!
So while the
<br />s and
</p>s aren’t necessary, they’re still legal.
Now with my DOCTYPE changed, I’m able to do lots of fun things, like remove
superfluous closing tags and attribute quotes and change my
div#footer tags to
I’m excited to explore HTML5 more in the months to come as I address other projects. To learn more about HTML5, see some of these links. * Yes, You Can Use HTML 5 via Jens Meiert’s blog * HTML 5 differences from HTML 4 via W3C * How to Learn HTML5 via Kroc Camen