Here are some interesting things I found from Dive into the HTML5 ebook:
Note: a couple of months ago, when I started reading this ebook, it was available under However, the author – Mark Pilgrim – is 410 Gone from web. However, his ‘Dive into …’ book were mirrored and they are still available.

  1. XHTML vs HTML parser
  2. Even if you declare your DOCTYPE as being XHTML, if you serve the page as Content-Type: text/html, it will be parsed by the HTML engine, not by the ‘draconic’ XHTML one. #

  3. Double negative to convert to Boolean #
  4. /* You can use the double-negative trick 
    to force the result to a Boolean value (true or false).*/
    return !!document.createElement('canvas').getContext;
  5. Skip ‘skip to content’ πŸ™‚
  6. No need to add ‘skip to content’ links at the beginning of your page if you are using HTML5’s nav element. The screen readers will handle it correctly. [#]

  7. Character encoding
  8. Web Server’s HTTP Header:

    Content-Type: text/html; charset="utf-8"

    Briefly, this says that the web server thinks it’s sending you an HTML document, and that it thinks the document uses the UTF-8 character encoding.

    <meta charset="utf-8" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    Briefly, this says that the web author thinks they have authored an HTML document using the UTF-8 character encoding.

    Both of these techniques still work in HTML5. The HTTP header is the preferred method, and it overrides the meta tag if present. But not everyone can set HTTP headers, so the meta tag is still around. [#]

  9. Document outline
  10. You can have multiple h1 tags in the same page. [#]
    You can check your HTML5 page outline using this outliner.

  11. Use Modernizr
  12. Modernizr is a small JavaScript library that detects the availability of native implementations for next-generation web technologies, i.e. features that stem from the HTML5 and CSS3 specifications. Many of these features are already implemented in at least one major browser (most of them in two or more), and what Modernizr does is, very simply, tell you whether the current browser has this feature natively implemented or not.

    if (Modernizr.canvas) 
    if (Modernizr.canvastext) 
    if ( 
    if (Modernizr.localstorage) 
    if (Modernizr.webworkers) 
    if (Modernizr.applicationcache) 
    if (Modernizr.geolocation) 
    if (
    if (Modernizr.input.placeholder) 
    if (Modernizr.input.autofocus) 
    if (Modernizr.history) 
    //Example video:
    if ( {
      // let's play some video! but what kind?
      if ( {
        // try WebM
      } else if ( {
        // try Ogg Theora + Vorbis in an Ogg container
      } else if ({
        // try H.264 video + AAC audio in an MP4 container

    More on the video element

  13. HTML5 canvas element
  14. It kind of looks like Flex without the Flash Builder πŸ™‚ To use it in older IE browsers as well, use ExploreCanvas [#]
    Here’s a nice application which lets you draw 3D sketches with animating strokes on HTML5 canvas.

Try the following example in your browser.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test js length</title>
#foo {width: 420px; height:70px; font-size:12px;}
#sbmt_btn {font-size:12px;}


<cfset str = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
Pellentesque bibendum tristique dignissim.">

String Length=#len(str)# characters

<form action="##" name="form1" id="form1" method="post" onsubmit="myfunc()">
	<textarea name="foo" id="foo" cols="30" rows="3">#str#</textarea> <br />
	<button type="submit" name="sbmt_btn" id="sbmt_btn">Submit</button>
<script type="text/javascript">
function myfunc()
	var myval = document.getElementById('foo').value;



Did you know the formula of love? It’s
Plotting this will result in a nicely hearth-shaped figure. The ultimate geek gift for his geek girlfriend!
I reproduced this plot using two methods: ColdFusion cfchart/cfchartseries/cfchartdata tags and a jQuery plotting library, called flot.

1. ColdFusion code

cflove.cfm (tested both on ColdFusion 8 and ColdFusion 9)

<cfchart format="flash" xaxistitle="X" yaxistitle="Y">
	<cfchartseries type="scatter">
		<cfloop index="x" from="-1" to="1" step="0.02">
			<cfset y1 = sqr(x^2)-sqr(1-x^2)>
			<cfchartdata item="#x#" value="#y1#">
	<cfchartseries type="scatter">
		<cfloop index="x" from="-1" to="1" step="0.02">
			<cfset y2 = sqr(x^2)+sqr(1-x^2)>
			<cfchartdata item="#x#" value="#y2#">

You will notice that the formula of love is composed by two curves:
-the upper part of the hearth: y = sqrt(x^2) – sqrt(1-x^2)
-the lower part of the hearth: y = sqrt(x^2) + sqrt(1-x^2)
The values of x are between -1 and 1.

Go ahead and load this file on your ColdFusion server. It will nicely draw the following image: (more…)