A Day with HTML 5 -or- I Can’t Believe It Validates!

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:

<div id="footer">
  <table id="summary">
    <tbody>
      <tr>
        <th>Row1</th>
        <td>Fun stuff</td>
      </tr>
      <tr>
        <th>Row2</th>
        <td>More stuff</td>
      </tr>
    </tbody>
  </table>
</div>

to this:

<footer>
  <table id=summary>
    <tr><th>Row1<td>Fun stuff
    <tr><th>Row2<td>More stuff
  </table>

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 <table> and a <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> for every <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> for that <p>? I don’t need quotes around my attributes? Now I know you’re messing with me. What? I don’t even need </div>? </body>? </html>?! We’ll 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 elements like <center> and <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 <nav>, <article>, and <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 HTML!

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

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

to

<!DOCTYPE html>

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#header and div#footer tags to <header> and <footer> tags.

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

This entry was posted in editorials, html5 and tagged , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>