<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>HTML 5 &#187; Tutorials</title>
	<atom:link href="http://www.htmlfive.net/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.htmlfive.net</link>
	<description>A central location for HTML5 news and updates</description>
	<lastBuildDate>Tue, 31 Aug 2010 10:55:33 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>The Road to HTML 5: Link Relations</title>
		<link>http://www.htmlfive.net/the-road-to-html-5-link-relations/</link>
		<comments>http://www.htmlfive.net/the-road-to-html-5-link-relations/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 16:30:50 +0000</pubDate>
		<dc:creator>Mark Pilgrim</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://blog.whatwg.org/?p=705</guid>
		<description><![CDATA[<p>Welcome back to my semi-regular column, "The Road to HTML 5," where I'll try to explain some of the <a href="http://dev.w3.org/html5/html4-differences/">new elements, attributes, and other features</a> in the upcoming HTML 5 specification.</p>

<p>The feature of the day is <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#linkTypes">link relations</a>.</p>

<p>In this article:</p>

<ul>
<li><a href="#what">What are link relations?</a></li>
<li><a href="#how">How can I use link relations?</a></li>
<li><a href="#new">Changes to link relations since HTML 4</a>
  <ul>
    <li><a href="#rel-alternate">rel=alternate</a></li>
    <li><a href="#rel-archives">rel=archives</a></li>
    <li><a href="#rel-author">rel=author (and the removal of the rev attribute)</a></li>
    <li><a href="#rel-external">rel=external</a></li>
    <li><a href="#rel-feed">rel=feed?</a></li>
    <li><a href="#rel-first">rel=first, last, prev, next, and up</a></li>
    <li><a href="#rel-icon">rel=icon</a></li>
    <li><a href="#rel-license">rel=license</a></li>
    <li><a href="#rel-nofollow">rel=nofollow</a></li>
    <li><a href="#rel-noreferrer">rel=noreferrer</a></li>
    <li><a href="#rel-pingback">rel=pingback</a></li>
    <li><a href="#rel-prefetch">rel=prefetch</a></li>
    <li><a href="#rel-search">rel=search</a></li>
    <li><a href="#rel-sidebar">rel=sidebar</a></li>
    <li><a href="#rel-tag">rel=tag</a></li>
    <li><a href="#rel-contact"><del>rel=contact</del></a></li>
  </ul>
</li>
<li><a href="#rel-extensions">Extending rel even further</a></li>
</ul>

<h3>What are link relations?</h3>

<p>Regular links (<code>&#60;a href&#62;</code>) simply point to another page. Link relations are a way to explain <em>why</em> you're pointing to another page. They finish the sentence "I'm pointing to this other page because..."</p>

<ul>
<li>...it's a stylesheet containing CSS rules that your browser should apply to this document</li>
<li>...it's a feed that contains the same content as this page, but in a standard subscribable format</li>
<li>...it's a translation of this page into another language</li>
<li>...it's the same content as this page, but in <abbr>PDF</abbr> format</li>
<li>...it's the next chapter of an online book that this page is also a part of</li>
</ul>

<p>And so on. HTML 5 breaks link relations <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/semantics.html#attr-link-rel">into two categories</a>:</p>

<blockquote cite="http://www.whatwg.org/specs/web-apps/current-work/multipage/semantics.html#attr-link-rel">
<p>Two categories of links can be created using the link element. <b>Links to external resources</b> are links to resources that are to be used to augment the current document, and <b>hyperlink links</b> are links to other documents. ...</p>
<p>The exact behavior for links to external resources depends on the exact relationship, as defined for the relevant link type.</p>
</blockquote>

<p>Of the examples I just gave, only the first (rel=stylesheet) is a link to an external resource. The rest are hyperlinks to other documents. You may wish to follow those links, or you may not, but they're not required in order to view the current page.</p>

<p>Common link relations include <code>&#60;link rel=stylesheet&#62;</code> (for importing <abbr>CSS</abbr> rules) and <code>&#60;link rel=alternate type=application/atom+xml&#62;</code> (for Atom feed autodiscovery). <a href="http://www.w3.org/TR/html401/types.html#type-links">HTML 4 defines several link relations</a>; others have been defined by the <a href="http://microformats.org/">microformats community</a>. HTML 5 attempts to consolidate all the known link relations, clean up their definitions (if necessary), and then provide a central registry for future proposals.</p>

<h3>How can I use link relations?</h3>

<p>Most often, link relations are seen on <code>&#60;link&#62;</code> elements within the <code>&#60;head&#62;</code> of a page. Some link relations can also be used on <code>&#60;a&#62;</code> elements, but this is uncommon even when allowed. HTML 5 also allows some relations on <code>&#60;area&#62;</code> elements, but this is even <em>less</em> common. (HTML 4 did not allow a <code>rel</code> attribute on <code>&#60;area&#62;</code> elements.)</p>

<p>See <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#linkTypes">the full chart of link relations</a> to check where you can use specific <code>rel</code> values.</p>

<h3>Changes to link relations since HTML 4</h3>

<p>Link relations were added to the HTML 5 spec in November 2006. (Back then the spec was still called "Web Applications 1.0.") <a href="http://html5.org/tools/web-apps-tracker?from=318&#38;to=319">r319</a> kicked off a flurry of <code>rel</code>-related activity. The original additions were primarily based on <a href="http://code.google.com/webstats/2005-12/linkrels.html">research of existing web content in December 2005</a>, using Google's cache of the web at the time. Since then, other relations have been added, and a few have been dropped.</p>

<h4>rel=alternate</h4>

<p><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#link-type-alternate">rel=alternate</a> has always been a strange hybrid of use cases, <a href="http://www.w3.org/TR/html401/types.html#type-links">even in HTML 4</a>. In HTML 5, its definition has been clarified and extended to more accurately describe existing web content. For example, using <code>rel=alternate</code> in conjunction with the <code>type</code> attribute indicates the same content in another format. Using <code>rel=alternate</code> in conjunction with <code>type=application/rss+xml</code> or <code>type=application/atom+xml</code> indicates an RSS or Atom feed, respectively.</p>

<p>HTML 5 also puts to rest a long-standing confusion about how to link to translations of documents. HTML 4 says to use the <code>lang</code> attribute in conjunction with <code>rel=alternate</code> to specify the language of the linked document, but this is incorrect. The <a href="http://www.w3.org/MarkUp/html4-updates/errata">HTML 4 Errata</a> lists four outright errors in the HTML 4 spec (along with several editorial nits); one of these outright errors is how to specify the language of a document linked with <code>rel=alternate</code> (The correct way, described in the HTML 4 Errata and now in HTML 5, is to use the <code>hreflang</code> attribute.) Unfortunately, these errata were never re-integrated into the HTML 4 spec, because <a href="http://twitter.com/diveintomark/status/1336512675">no one in the W3C HTML Working Group was working on HTML anymore</a>.</p>

<ul>
<li><a href="http://html5.org/tools/web-apps-tracker?from=323&#38;to=324">r324</a>: <code>rel=alternate</code> added to HTML 5</li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=484&#38;to=485">r485</a> defines how to use the <code>media</code> attribute in conjunction with <code>rel=alternate</code></li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=1941&#38;to=1942">r1942</a> make the <code>title</code> attribute required for <code>rel="alternate stylesheet"</code>.</li>
</ul>

<h4>rel=archives</h4>

<p><i>New in HTML 5</i></p>

<p><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#link-type-archives">rel=archives</a> "indicates that the referenced document describes a collection of records, documents, or other materials of historical interest. A blog's index page could link to an index of the blog's past posts with rel="archives"."</p>

<ul>
<li><a href="http://html5.org/tools/web-apps-tracker?from=319&#38;to=320">r320</a>: <code>rel=archives</code> added to HTML 5</li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=325&#38;to=326">r326</a>: more thorough definition</li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=327&#38;to=328">r328</a> adds the above-quoted text</li>
</ul>

<h4>rel=author (and the removal of the rev attribute)</h4>

<p><i>New in HTML 5</i></p>

<p><code>rel=author</code> is used to link to information about the author of the page. This can be a <code>mailto:</code> address, though it doesn't have to be. It could simply link to a contact form or "about the author" page.</p>

<p><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#link-type-author">rel=author</a> is equivalent to the <code>rev=made</code> link relation defined in <a href="http://www.w3.org/TR/REC-html32.html">HTML 3.2</a>. Despite popular belief, HTML 4 <em>does not include <code>rev=made</code></em>, effectively obsoleting it. (You can <a href="http://www.w3.org/TR/html401/html40.txt">search the entire spec for the word "made"</a> if you don't believe me.)</p>

<p>Given that <code>rev=made</code> was <a href="http://code.google.com/webstats/2005-12/linkrels.html">the only significant non-typo usage of the <code>rev</code> attribute</a>, HTML 5 added <code>rel=author</code> to make up for the loss of <code>rev=made</code> in HTML 4, thus allowing the working group to obsolete the <code>rev</code> attribute altogether. Other than the un/semi/sortof-documented <code>rev=made</code> value, <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-July/006892.html">people typo the "rev" attribute more often than they intentionally use it</a>, which suggests that the world would be better off if validators could flag it as non-conforming.</p>

<p>The decision to drop the <code>rev</code> attribute seems especially controversial. The same question flares up again and again on the working group's mailing list: "what happened to the <code>rev</code> attribute?" But in the face of almost-universal misunderstanding (among people who try to use it) and apathy (among everyone else), no one has ever made a convincing case for keeping it that didn't boil down to "I wish the world were different." Hey, so do I, man. So do I.</p>

<ul>
<li><a href="http://html5.org/tools/web-apps-tracker?from=328&#38;to=329">r329</a>: <code>rel=author</code> added to HTML 5</li>
<li><a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2005-July/004316.html">WA1: rev attribute</a> (and <a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2007-October/012975.html">followup two years later</a>)</li>
<li><a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-July/thread.html#6886">Where did the "rev" attribute go</a>?</li>
<li><a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2008-May/thread.html#14823">Removing @rev</a></li>
<li><a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2008-November/thread.html#17290">Absent rev</a>?</li>
</ul>

<h4>rel=external</h4>

<p><i>New in HTML 5</i></p>

<p><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#link-type-external">rel=external</a> "indicates that the link is leading to a document that is not part of the site that the current document forms a part of." I believe it was first popularized by <a href="http://www.wordpress.org/">WordPress</a>, which uses it on links left by commenters. I could not find any discussion of it in the HTML working group mailing list archives. Both its existence and its definition appear to be entirely uncontroversial.</p>

<ul>
<li><a href="http://html5.org/tools/web-apps-tracker?from=318&#38;to=319">r319</a>: <code>rel=external</code> added to HTML 5</li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=334&#38;to=335">r334</a>: more thorough description</li>
</ul>

<h4>rel=feed?</h4>

<p><i>New in HTML 5, but may not be long for this world</i></p>

<p><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#link-type-feed">rel=feed</a> "indicates that the referenced document is a syndication feed." Right away, you're thinking, "Hey, I thought you were supposed to use <code>rel=alternate type=application/atom+xml</code> to indicate that the referenced document is a syndication feed." In fact, that's what everyone does, and that's what all browsers support. Firefox 3 is the only browser that supports <code>rel=feed</code>. (It also supports <code>rel=alternate type=application/atom+xml</code>.) The <code>rel=feed</code> variant was <a href="http://www.imc.org/atom-syntax/mail-archive/msg15042.html">proposed in the Atom working group in 2005</a> and somehow found its way into HTML 5. Just yesterday, I <a href="http://krijnhoetmer.nl/irc-logs/whatwg/20090416#l-504">was discussing whether HTML 5 should drop rel=feed</a> due to lack of browser implementation and complete and utter lack of author awareness.</p>

<ul>
<li><a href="http://html5.org/tools/web-apps-tracker?from=318&#38;to=319">r319</a>: <code>rel=feed</code> added to HTML 5</li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=334&#38;to=335">r335</a>: more thorough definition</li>
<li><a href="http://www.imc.org/atom-syntax/mail-archive/msg15042.html">Autodiscovery paces</a></li>
<li><a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-November/thread.html#8080">Inferring rel="feed" from the media type</a></li>
<li><a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-November/thread.html#8129">PaceEntryMediatype</a> (<a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-December/thread.html#8166">2</a>, <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-December/thread.html#8204">3</a>)</li>
<li><a href="http://krijnhoetmer.nl/irc-logs/whatwg/20090416#l-504">IRC chat about browser compatibility and usage within existing web content</a> (<a href="http://krijnhoetmer.nl/irc-logs/whatwg/20090417#l-3">continued on next page</a>)</li>
</ul>

<h4>rel=first, last, prev, next, and up</h4>

<p>HTML 4 defined <a href="http://www.w3.org/TR/html401/types.html#type-links"><code>rel=start</code>, <code>rel=prev</code>, and <code>rel=next</code></a> to define relations between pages that are part of a series (like chapters of a book, or even posts on a blog). The only one that was ever used correctly was <code>rel=next</code>. People used <code>rel=previous</code> instead of <code>rel=prev</code>; they used <code>rel=begin</code> and <code>rel=first</code> instead of <code>rel=start</code>; they used <code>rel=end</code> instead of <code>rel=last</code>. Oh, and -- all by themselves -- they made up <code>rel=up</code> to point to a "parent" page.</p>

<p>HTML 5 includes <code>rel=first</code>, which was the most variation of the different ways to say "first page in a series." (<code>rel=start</code> is a non-conforming synonym, for backward compatibility.) Also <code>rel=prev</code> and <code>rel=next</code>, just like HTML 4 (but mentioning <code>rel=previous</code> for back-compat). It also adds <code>rel=last</code> (the last in a series, mirroring <code>rel=first</code>) and <code>rel=up</code>.</p>

<p>The best way to think of <code>rel=up</code> is to look at your breadcrumb navigation (or at least imagine it). Your home page is probably the first page in your breadcrumbs, and the current page is at the tail end. <code>rel=up</code> points to the next-to-the-last page in the breadcrumbs.</p>

<ul>
<li><a href="http://html5.org/tools/web-apps-tracker?from=318&#38;to=319">r319</a>: <code>rel=first/prev/next/last</code> added to HTML 5</li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=319&#38;to=320">r320</a>: <code>rel=up</code> added to HTML 5</li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=1125&#38;to=1126">r1126</a> and <a href="http://html5.org/tools/web-apps-tracker?from=1126&#38;to=1127">r1127</a> make it clear that <code>rel=first/prev/next/last</code> refer to any sequence of pages, not just a hierarchical structure.</li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=1129&#38;to=1130">r1130</a> makes it legal to duplicate the <code>up</code> keyword in a single <code>rel</code> attribute.</li>
</ul>

<h4>rel=icon</h4>

<p><i>New in HTML 5</i></p>

<p><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#rel-icon">rel=icon</a> is the <a href="http://code.google.com/webstats/2005-12/linkrels.html">second most popular link relation</a>, after <code>rel=stylesheet</code>. It is usually found together with <code>shortcut</code>, like so:</p>

<p><code>&#60;link rel="shortcut icon" href="/favicon.ico"&#62;</code></p>

<p>All major browsers support this usage to associate a small icon with the page (usually displayed in the browser's location bar next to the URL).</p>

<p>Also new in HTML 5: the <code>sizes</code> attribute can be used in conjunction with the <code>icon</code> relationship to indicate the size of the referenced icon. [<a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#rel-icon"><code>sizes</code> example</a>]</p>

<ul>
<li><a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2008-April/thread.html#14602">&#60;link rel=icon width="" height=""&#62;</a> (initial proposal, later changed to <code>sizes</code>)</li>
<li><a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2008-May/thread.html#14646">Re: &#60;link rel=icon width="" height=""&#62;</a></li>
<li><a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2008-May/thread.html#14740">&#60;link rel=icon sizes=?&#62; What if sizes is incorrect?</a></li>
<li><a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2008-May/014918.html">The sizes="" attribute for rel=icon</a></li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=338&#38;to=339">r339</a>: <code>rel=icon</code> added to HTML 5</li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=1557&#38;to=1558">r1558</a> adds the <code>sizes</code> attribute, and <a href="http://html5.org/tools/web-apps-tracker?from=1558&#38;to=1559">r1559</a> adds an example</li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=1711&#38;to=1712">r1712</a> says that, if the browser decides that multiple icons are appropriate and equally desirable, the last one listed should be used.</li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=1712&#38;to=1713">r1713</a> further explains how to determine precedence if multiple icons are listed.</li>
</ul>

<h4>rel=license</h4>

<p><i>New in HTML 5</i></p>

<p><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#link-type-license">rel=license</a> was <a href="http://microformats.org/wiki/rel-license">invented by the microformats community</a>. It "indicates that the referenced document provides the copyright license terms under which the current document is provided."</p>
  
<ul>
<li><a href="http://tantek.com/presentations/2004etech/realworldsemanticspres.html">real world semantics</a>, the presentation that launched a thousand ships</li>
<li><a href="http://tantek.com/log/2004/02.html#d25t1805">creative commons supports rel="license"</a></li>
<li><a href="http://microformats.org/wiki/rel-license">rel="license" spec on microformats.org</a></li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=339&#38;to=340">r340</a>: <code>rel=license</code> added to HTML 5</li>
<li><a href="http://microformats.org/wiki/rel-license-issues">rel-license-issues</a></li>
</ul>

<h4>rel=nofollow</h4>

<p><i>New in HTML 5</i></p>

<p><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#link-type-nofollow">rel=nofollow</a> "indicates that the link is not endorsed by the original author or publisher of the page, or that the link to the referenced document was included primarily because of a commercial relationship between people affiliated with the two pages." It was <a href="http://googleblog.blogspot.com/2005/01/preventing-comment-spam.html">invented by Google</a> and <a href="http://microformats.org/wiki/rel-nofollow">standardized within the microformats community</a>. The thinking was that if "nofollow" links did not pass on PageRank, spammers would give up trying to post spam comments on weblogs. That didn't happen, but <code>rel=nofollow</code> persists. Many popular blogging systems default to adding <code>rel=nofollow</code> to links added by commenters.</p>

<ul>
<li><a href="http://html5.org/tools/web-apps-tracker?from=340&#38;to=341">r341</a>: <code>rel=nofollow</code> added to HTML 5</li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=1707&#38;to=1708">r1708</a> added the clause about commercial relationships.</li>
</ul>

<h4>rel=noreferrer</h4>

<p><i>New in HTML 5</i></p>

<p><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#link-type-noreferrer">rel=noreferrer</a> "indicates that the no referrer information is to be leaked when following the link." No browser currently supports this. [<a href="http://wearehugh.com/public/2009/04/rel-noreferrer.html">rel=noreferrer test case</a>]</p>

<ul>
<li><a href="http://html5.org/tools/web-apps-tracker?from=1118&#38;to=1119">r1119</a>: <code>rel=noreferrer</code> added to HTML 5</li>
<li><a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-January/005483.html">no referer attrribute for &#60;a&#62;, same reason as ping</a> - initial discussion of a mechanism for blocking referrer information on individual links</li>
<li><a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2007-November/013021.html">several messages about a way to disable referer headers for links</a></li>
<li>"<a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2007-November/013071.html">I don't think that spelling the attribute "noreferer" is consistent. It should be "noreferrer".</a>"</li>
<li>"<a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2007-November/013072.html">I'll switch to [no]referrer.</a>"</li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=1949&#38;to=1950">r1950</a> extends <code>rel=noreferrer</code> to also blow away the 'opener' when used with target=_blank</li>
</ul>

<h4>rel=pingback</h4>

<p><i>New in HTML 5</i></p>

<p><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#link-type-pingback">rel=pingback</a> specifies the address of a "pingback" server. As explained in <a href="http://hixie.ch/specs/pingback/pingback-1.0">the Pingback specification</a>, "The pingback system is a way for a blog to be automatically notified when other Web sites link to it. ... It enables reverse linking -- a way of going back up a chain of links rather than merely drilling down."</p>

<p>Blogging systems, notably WordPress, implement the pingback mechanism to notify authors that you have linked to them when creating a new blog post.</p>

<ul>
<li><a href="http://html5.org/tools/web-apps-tracker?from=342&#38;to=343">r343</a>: <code>rel=pingback</code> added to HTML 5</li>
<li><a href="http://hixie.ch/specs/pingback/pingback-1.0">Pingback 1.0 specification</a></li>
<li><a href="http://www.optiniche.com/blog/117/wordpress-trackback-tutorial/">WordPress Trackback Tutorial</a></li>
</ul>

<h4>rel=prefetch</h4>

<p><i>New in HTML 5</i></p>

<p><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#link-type-prefetch">rel=prefetch</a> "indicates that preemptively fetching and caching the specified resource is likely to be beneficial, as it is highly likely that the user will require this resource." Search engines sometimes add <code>&#60;link rel=prefetch href="<i>URL of top search result</i>"&#62;</code> to the search results page if they feel that the top result is wildly more popular than any other. For example: using Firefox, <a href="http://www.google.com/search?q=cnn">search Google for CNN</a>; view source; search for the keyword "prefetch".</p>

<p>Mozilla Firefox is the only current browser that supports <code>rel=prefetch</code>.</p>

<ul>
<li><a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2004-June/000190.html">What improves Web applications?</a> "A big plus point would be to prefetch the next page so it loads immediately the 'next' button is clicked."</li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=344&#38;to=345">r345</a>: <code>rel=prefetch</code> added to HTML 5</li>
<li><a href="https://developer.mozilla.org/En/Link_prefetching_FAQ">Link prefetching FAQ</a> on Mozilla Developer Center</li>
<li><a href="http://browserspy.dk/prefetch.php">test whether your browser supports <code>rel=prefetch</code></a></li>
</ul>

<h4>rel=search</h4>

<p><i>New in HTML 5</i></p>

<p><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#link-type-search">rel=search</a> "indicates that the referenced document provides an interface specifically for searching the document and its related resources." Specifically, if you want <code>rel=search</code> to do anything useful, it should point to an <a href="http://www.opensearch.org/">OpenSearch</a> document that describes how a browser could construct a URL to search the current site for a given keyword.</p>

<p>OpenSearch (and <code>rel=search</code> links that point to OpenSearch description documents) is supported in Microsoft Internet Explorer since version 7 and Mozilla Firefox since version 2.</p>

<ul>
<li><a href="http://www.opensearch.org/Specifications/OpenSearch/1.1#Autodiscovery_in_HTML.2FXHTML">OpenSearch: Autodiscovery in HTML/XHTML</a></li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=344&#38;to=345">r345</a>: <code>rel=search</code> added to HTML 5</li>
<li><a href="https://developer.mozilla.org/en/Creating_OpenSearch_plugins_for_Firefox">Creating OpenSearch plugins for Firefox</a></li>
<li><a href="https://addons.mozilla.org/en-US/firefox/browse/type:4/cat:all?show=20&#38;sort=popular">Available search plugins for Firefox</a></li>
<li><a href="http://www.microsoft.com/windows/ie/searchguide/en-en/default.mspx">Search Providers for Microsoft Internet Explorer</a></li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=483&#38;to=484">r484</a> adds a note about OpenSearch documents in particular</li>
</ul>

<h4>rel=sidebar</h4>

<p><i>New in HTML 5</i></p>

<p><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#link-type-sidebar">rel=sidebar</a> "indicates that the referenced document, if retrieved, is intended to be shown in a secondary browsing context (if possible), instead of in the current browsing context." What does that mean? In Opera and Mozilla Firefox, it means "when I click this link, prompt the user to create a bookmark that, when selected from the Bookmarks menu, opens the linked document in a browser sidebar." (Opera actually calls it the "panel" instead of the "sidebar.")</p>

<p>Internet Explorer, Safari, and Chrome ignore <code>rel=sidebar</code> and just treat it as a regular link. [<a href="http://wearehugh.com/public/2009/04/rel-sidebar.html">rel=sidebar test case</a>]</p>

<ul>
<li><a href="http://html5.org/tools/web-apps-tracker?from=345&#38;to=346">r346</a>: <code>rel=sidebar</code> added to HTML 5</li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=667&#38;to=668">r668</a> revamps the definition based on the concept of a "secondary browsing context."</li>
</ul>

<h4>rel=tag</h4>

<p><i>New in HTML 5</i></p>

<p><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#link-type-tag">rel=tag</a> "indicates that the tag that the referenced document represents applies to the current document." Marking up "tags" (category keywords) with the <code>rel</code> attribute was <a href="http://www.powazek.com/2005/07/000532.html">invented by Technorati</a> to help them categorize blog posts. Early blogs and tutorials thus referred to them as "Technorati tags." (You read that right: a commercial company convinced the entire world to add metadata that made the company's job easier. Nice work if you can get it!) The syntax was later <a href="http://microformats.org/wiki/rel-tag">standardized within the microformats community</a>, where it was simply called "rel=tag".</p>

<p>Most blogging systems that allow associating categories, keywords, or tags with individual posts will mark them up with <code>rel=tag</code> links. Browsers do not do anything special with them, but they're really designed for search engines to use as a signal of what the page is about.</p>

<ul>
<li><a href="http://microformats.org/wiki/rel-tag">rel-tag microformat specification</a></li>
<li><a href="http://microformats.org/wiki/rel-tag-faq">rel-tag FAQ</a></li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=345&#38;to=346">r346</a>: <code>rel=tag</code> added to HTML 5</li>
</ul>

<h4><del>rel=contact</del></h4>

<p><code>rel=contact</code> was briefly part of HTML 5, but <a href="http://html5.org/tools/web-apps-tracker?from=1710&#38;to=1711">r1711</a> removed it because it conflicted with the same-named <a href="http://gmpg.org/xfn/">XFN relationship</a>.</p>

<h3>Extending rel even further</h3>

<p>There seems to be an infinite supply of ideas for new link relations. In an attempt to prevent people from <a href="http://developer.apple.com/safari/library/documentation/AppleApplications/Reference/SafariWebContent/ConfiguringWebApplications/chapter_8_section_2.html">just making shit up</a>, the WHATWG <a href="http://wiki.whatwg.org/wiki/RelExtensions">maintains a registry of proposed <code>rel</code> values</a> and <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#other-link-types">defines the process for getting them accepted</a>.</p>
]]></description>
			<content:encoded><![CDATA[<p>Welcome back to my semi-regular column, "The Road to HTML 5," where I'll try to explain some of the <a href="http://dev.w3.org/html5/html4-differences/">new elements, attributes, and other features</a> in the upcoming HTML 5 specification.</p>

<p>The feature of the day is <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#linkTypes">link relations</a>.</p>

<p>In this article:</p>

<ul>
<li><a href="#what">What are link relations?</a></li>
<li><a href="#how">How can I use link relations?</a></li>
<li><a href="#new">Changes to link relations since HTML 4</a>
  <ul>
    <li><a href="#rel-alternate">rel=alternate</a></li>
    <li><a href="#rel-archives">rel=archives</a></li>
    <li><a href="#rel-author">rel=author (and the removal of the rev attribute)</a></li>
    <li><a href="#rel-external">rel=external</a></li>
    <li><a href="#rel-feed">rel=feed?</a></li>
    <li><a href="#rel-first">rel=first, last, prev, next, and up</a></li>
    <li><a href="#rel-icon">rel=icon</a></li>
    <li><a href="#rel-license">rel=license</a></li>
    <li><a href="#rel-nofollow">rel=nofollow</a></li>
    <li><a href="#rel-noreferrer">rel=noreferrer</a></li>
    <li><a href="#rel-pingback">rel=pingback</a></li>
    <li><a href="#rel-prefetch">rel=prefetch</a></li>
    <li><a href="#rel-search">rel=search</a></li>
    <li><a href="#rel-sidebar">rel=sidebar</a></li>
    <li><a href="#rel-tag">rel=tag</a></li>
    <li><a href="#rel-contact"><del>rel=contact</del></a></li>
  </ul>
</li>
<li><a href="#rel-extensions">Extending rel even further</a></li>
</ul>

<h3>What are link relations?</h3>

<p>Regular links (<code>&lt;a href&gt;</code>) simply point to another page. Link relations are a way to explain <em>why</em> you're pointing to another page. They finish the sentence "I'm pointing to this other page because..."</p>

<ul>
<li>...it's a stylesheet containing CSS rules that your browser should apply to this document</li>
<li>...it's a feed that contains the same content as this page, but in a standard subscribable format</li>
<li>...it's a translation of this page into another language</li>
<li>...it's the same content as this page, but in <abbr>PDF</abbr> format</li>
<li>...it's the next chapter of an online book that this page is also a part of</li>
</ul>

<p>And so on. HTML 5 breaks link relations <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/semantics.html#attr-link-rel">into two categories</a>:</p>

<blockquote cite="http://www.whatwg.org/specs/web-apps/current-work/multipage/semantics.html#attr-link-rel">
<p>Two categories of links can be created using the link element. <b>Links to external resources</b> are links to resources that are to be used to augment the current document, and <b>hyperlink links</b> are links to other documents. ...</p>
<p>The exact behavior for links to external resources depends on the exact relationship, as defined for the relevant link type.</p>
</blockquote>

<p>Of the examples I just gave, only the first (rel=stylesheet) is a link to an external resource. The rest are hyperlinks to other documents. You may wish to follow those links, or you may not, but they're not required in order to view the current page.</p>

<p>Common link relations include <code>&lt;link rel=stylesheet&gt;</code> (for importing <abbr>CSS</abbr> rules) and <code>&lt;link rel=alternate type=application/atom+xml&gt;</code> (for Atom feed autodiscovery). <a href="http://www.w3.org/TR/html401/types.html#type-links">HTML 4 defines several link relations</a>; others have been defined by the <a href="http://microformats.org/">microformats community</a>. HTML 5 attempts to consolidate all the known link relations, clean up their definitions (if necessary), and then provide a central registry for future proposals.</p>

<h3>How can I use link relations?</h3>

<p>Most often, link relations are seen on <code>&lt;link&gt;</code> elements within the <code>&lt;head&gt;</code> of a page. Some link relations can also be used on <code>&lt;a&gt;</code> elements, but this is uncommon even when allowed. HTML 5 also allows some relations on <code>&lt;area&gt;</code> elements, but this is even <em>less</em> common. (HTML 4 did not allow a <code>rel</code> attribute on <code>&lt;area&gt;</code> elements.)</p>

<p>See <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#linkTypes">the full chart of link relations</a> to check where you can use specific <code>rel</code> values.</p>

<h3>Changes to link relations since HTML 4</h3>

<p>Link relations were added to the HTML 5 spec in November 2006. (Back then the spec was still called "Web Applications 1.0.") <a href="http://html5.org/tools/web-apps-tracker?from=318&amp;to=319">r319</a> kicked off a flurry of <code>rel</code>-related activity. The original additions were primarily based on <a href="http://code.google.com/webstats/2005-12/linkrels.html">research of existing web content in December 2005</a>, using Google's cache of the web at the time. Since then, other relations have been added, and a few have been dropped.</p>

<h4>rel=alternate</h4>

<p><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#link-type-alternate">rel=alternate</a> has always been a strange hybrid of use cases, <a href="http://www.w3.org/TR/html401/types.html#type-links">even in HTML 4</a>. In HTML 5, its definition has been clarified and extended to more accurately describe existing web content. For example, using <code>rel=alternate</code> in conjunction with the <code>type</code> attribute indicates the same content in another format. Using <code>rel=alternate</code> in conjunction with <code>type=application/rss+xml</code> or <code>type=application/atom+xml</code> indicates an RSS or Atom feed, respectively.</p>

<p>HTML 5 also puts to rest a long-standing confusion about how to link to translations of documents. HTML 4 says to use the <code>lang</code> attribute in conjunction with <code>rel=alternate</code> to specify the language of the linked document, but this is incorrect. The <a href="http://www.w3.org/MarkUp/html4-updates/errata">HTML 4 Errata</a> lists four outright errors in the HTML 4 spec (along with several editorial nits); one of these outright errors is how to specify the language of a document linked with <code>rel=alternate</code> (The correct way, described in the HTML 4 Errata and now in HTML 5, is to use the <code>hreflang</code> attribute.) Unfortunately, these errata were never re-integrated into the HTML 4 spec, because <a href="http://twitter.com/diveintomark/status/1336512675">no one in the W3C HTML Working Group was working on HTML anymore</a>.</p>

<ul>
<li><a href="http://html5.org/tools/web-apps-tracker?from=323&amp;to=324">r324</a>: <code>rel=alternate</code> added to HTML 5</li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=484&amp;to=485">r485</a> defines how to use the <code>media</code> attribute in conjunction with <code>rel=alternate</code></li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=1941&amp;to=1942">r1942</a> make the <code>title</code> attribute required for <code>rel="alternate stylesheet"</code>.</li>
</ul>

<h4>rel=archives</h4>

<p><i>New in HTML 5</i></p>

<p><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#link-type-archives">rel=archives</a> "indicates that the referenced document describes a collection of records, documents, or other materials of historical interest. A blog's index page could link to an index of the blog's past posts with rel="archives"."</p>

<ul>
<li><a href="http://html5.org/tools/web-apps-tracker?from=319&amp;to=320">r320</a>: <code>rel=archives</code> added to HTML 5</li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=325&amp;to=326">r326</a>: more thorough definition</li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=327&amp;to=328">r328</a> adds the above-quoted text</li>
</ul>

<h4>rel=author (and the removal of the rev attribute)</h4>

<p><i>New in HTML 5</i></p>

<p><code>rel=author</code> is used to link to information about the author of the page. This can be a <code>mailto:</code> address, though it doesn't have to be. It could simply link to a contact form or "about the author" page.</p>

<p><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#link-type-author">rel=author</a> is equivalent to the <code>rev=made</code> link relation defined in <a href="http://www.w3.org/TR/REC-html32.html">HTML 3.2</a>. Despite popular belief, HTML 4 <em>does not include <code>rev=made</code></em>, effectively obsoleting it. (You can <a href="http://www.w3.org/TR/html401/html40.txt">search the entire spec for the word "made"</a> if you don't believe me.)</p>

<p>Given that <code>rev=made</code> was <a href="http://code.google.com/webstats/2005-12/linkrels.html">the only significant non-typo usage of the <code>rev</code> attribute</a>, HTML 5 added <code>rel=author</code> to make up for the loss of <code>rev=made</code> in HTML 4, thus allowing the working group to obsolete the <code>rev</code> attribute altogether. Other than the un/semi/sortof-documented <code>rev=made</code> value, <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-July/006892.html">people typo the "rev" attribute more often than they intentionally use it</a>, which suggests that the world would be better off if validators could flag it as non-conforming.</p>

<p>The decision to drop the <code>rev</code> attribute seems especially controversial. The same question flares up again and again on the working group's mailing list: "what happened to the <code>rev</code> attribute?" But in the face of almost-universal misunderstanding (among people who try to use it) and apathy (among everyone else), no one has ever made a convincing case for keeping it that didn't boil down to "I wish the world were different." Hey, so do I, man. So do I.</p>

<ul>
<li><a href="http://html5.org/tools/web-apps-tracker?from=328&amp;to=329">r329</a>: <code>rel=author</code> added to HTML 5</li>
<li><a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2005-July/004316.html">WA1: rev attribute</a> (and <a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2007-October/012975.html">followup two years later</a>)</li>
<li><a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-July/thread.html#6886">Where did the "rev" attribute go</a>?</li>
<li><a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2008-May/thread.html#14823">Removing @rev</a></li>
<li><a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2008-November/thread.html#17290">Absent rev</a>?</li>
</ul>

<h4>rel=external</h4>

<p><i>New in HTML 5</i></p>

<p><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#link-type-external">rel=external</a> "indicates that the link is leading to a document that is not part of the site that the current document forms a part of." I believe it was first popularized by <a href="http://www.wordpress.org/">WordPress</a>, which uses it on links left by commenters. I could not find any discussion of it in the HTML working group mailing list archives. Both its existence and its definition appear to be entirely uncontroversial.</p>

<ul>
<li><a href="http://html5.org/tools/web-apps-tracker?from=318&amp;to=319">r319</a>: <code>rel=external</code> added to HTML 5</li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=334&amp;to=335">r334</a>: more thorough description</li>
</ul>

<h4>rel=feed?</h4>

<p><i>New in HTML 5, but may not be long for this world</i></p>

<p><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#link-type-feed">rel=feed</a> "indicates that the referenced document is a syndication feed." Right away, you're thinking, "Hey, I thought you were supposed to use <code>rel=alternate type=application/atom+xml</code> to indicate that the referenced document is a syndication feed." In fact, that's what everyone does, and that's what all browsers support. Firefox 3 is the only browser that supports <code>rel=feed</code>. (It also supports <code>rel=alternate type=application/atom+xml</code>.) The <code>rel=feed</code> variant was <a href="http://www.imc.org/atom-syntax/mail-archive/msg15042.html">proposed in the Atom working group in 2005</a> and somehow found its way into HTML 5. Just yesterday, I <a href="http://krijnhoetmer.nl/irc-logs/whatwg/20090416#l-504">was discussing whether HTML 5 should drop rel=feed</a> due to lack of browser implementation and complete and utter lack of author awareness.</p>

<ul>
<li><a href="http://html5.org/tools/web-apps-tracker?from=318&amp;to=319">r319</a>: <code>rel=feed</code> added to HTML 5</li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=334&amp;to=335">r335</a>: more thorough definition</li>
<li><a href="http://www.imc.org/atom-syntax/mail-archive/msg15042.html">Autodiscovery paces</a></li>
<li><a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-November/thread.html#8080">Inferring rel="feed" from the media type</a></li>
<li><a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-November/thread.html#8129">PaceEntryMediatype</a> (<a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-December/thread.html#8166">2</a>, <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-December/thread.html#8204">3</a>)</li>
<li><a href="http://krijnhoetmer.nl/irc-logs/whatwg/20090416#l-504">IRC chat about browser compatibility and usage within existing web content</a> (<a href="http://krijnhoetmer.nl/irc-logs/whatwg/20090417#l-3">continued on next page</a>)</li>
</ul>

<h4>rel=first, last, prev, next, and up</h4>

<p>HTML 4 defined <a href="http://www.w3.org/TR/html401/types.html#type-links"><code>rel=start</code>, <code>rel=prev</code>, and <code>rel=next</code></a> to define relations between pages that are part of a series (like chapters of a book, or even posts on a blog). The only one that was ever used correctly was <code>rel=next</code>. People used <code>rel=previous</code> instead of <code>rel=prev</code>; they used <code>rel=begin</code> and <code>rel=first</code> instead of <code>rel=start</code>; they used <code>rel=end</code> instead of <code>rel=last</code>. Oh, and -- all by themselves -- they made up <code>rel=up</code> to point to a "parent" page.</p>

<p>HTML 5 includes <code>rel=first</code>, which was the most variation of the different ways to say "first page in a series." (<code>rel=start</code> is a non-conforming synonym, for backward compatibility.) Also <code>rel=prev</code> and <code>rel=next</code>, just like HTML 4 (but mentioning <code>rel=previous</code> for back-compat). It also adds <code>rel=last</code> (the last in a series, mirroring <code>rel=first</code>) and <code>rel=up</code>.</p>

<p>The best way to think of <code>rel=up</code> is to look at your breadcrumb navigation (or at least imagine it). Your home page is probably the first page in your breadcrumbs, and the current page is at the tail end. <code>rel=up</code> points to the next-to-the-last page in the breadcrumbs.</p>

<ul>
<li><a href="http://html5.org/tools/web-apps-tracker?from=318&amp;to=319">r319</a>: <code>rel=first/prev/next/last</code> added to HTML 5</li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=319&amp;to=320">r320</a>: <code>rel=up</code> added to HTML 5</li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=1125&amp;to=1126">r1126</a> and <a href="http://html5.org/tools/web-apps-tracker?from=1126&amp;to=1127">r1127</a> make it clear that <code>rel=first/prev/next/last</code> refer to any sequence of pages, not just a hierarchical structure.</li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=1129&amp;to=1130">r1130</a> makes it legal to duplicate the <code>up</code> keyword in a single <code>rel</code> attribute.</li>
</ul>

<h4>rel=icon</h4>

<p><i>New in HTML 5</i></p>

<p><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#rel-icon">rel=icon</a> is the <a href="http://code.google.com/webstats/2005-12/linkrels.html">second most popular link relation</a>, after <code>rel=stylesheet</code>. It is usually found together with <code>shortcut</code>, like so:</p>

<p><code>&lt;link rel="shortcut icon" href="/favicon.ico"&gt;</code></p>

<p>All major browsers support this usage to associate a small icon with the page (usually displayed in the browser's location bar next to the URL).</p>

<p>Also new in HTML 5: the <code>sizes</code> attribute can be used in conjunction with the <code>icon</code> relationship to indicate the size of the referenced icon. [<a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#rel-icon"><code>sizes</code> example</a>]</p>

<ul>
<li><a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2008-April/thread.html#14602">&lt;link rel=icon width="" height=""&gt;</a> (initial proposal, later changed to <code>sizes</code>)</li>
<li><a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2008-May/thread.html#14646">Re: &lt;link rel=icon width="" height=""&gt;</a></li>
<li><a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2008-May/thread.html#14740">&lt;link rel=icon sizes=?&gt; What if sizes is incorrect?</a></li>
<li><a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2008-May/014918.html">The sizes="" attribute for rel=icon</a></li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=338&amp;to=339">r339</a>: <code>rel=icon</code> added to HTML 5</li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=1557&amp;to=1558">r1558</a> adds the <code>sizes</code> attribute, and <a href="http://html5.org/tools/web-apps-tracker?from=1558&amp;to=1559">r1559</a> adds an example</li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=1711&amp;to=1712">r1712</a> says that, if the browser decides that multiple icons are appropriate and equally desirable, the last one listed should be used.</li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=1712&amp;to=1713">r1713</a> further explains how to determine precedence if multiple icons are listed.</li>
</ul>

<h4>rel=license</h4>

<p><i>New in HTML 5</i></p>

<p><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#link-type-license">rel=license</a> was <a href="http://microformats.org/wiki/rel-license">invented by the microformats community</a>. It "indicates that the referenced document provides the copyright license terms under which the current document is provided."</p>
  
<ul>
<li><a href="http://tantek.com/presentations/2004etech/realworldsemanticspres.html">real world semantics</a>, the presentation that launched a thousand ships</li>
<li><a href="http://tantek.com/log/2004/02.html#d25t1805">creative commons supports rel="license"</a></li>
<li><a href="http://microformats.org/wiki/rel-license">rel="license" spec on microformats.org</a></li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=339&amp;to=340">r340</a>: <code>rel=license</code> added to HTML 5</li>
<li><a href="http://microformats.org/wiki/rel-license-issues">rel-license-issues</a></li>
</ul>

<h4>rel=nofollow</h4>

<p><i>New in HTML 5</i></p>

<p><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#link-type-nofollow">rel=nofollow</a> "indicates that the link is not endorsed by the original author or publisher of the page, or that the link to the referenced document was included primarily because of a commercial relationship between people affiliated with the two pages." It was <a href="http://googleblog.blogspot.com/2005/01/preventing-comment-spam.html">invented by Google</a> and <a href="http://microformats.org/wiki/rel-nofollow">standardized within the microformats community</a>. The thinking was that if "nofollow" links did not pass on PageRank, spammers would give up trying to post spam comments on weblogs. That didn't happen, but <code>rel=nofollow</code> persists. Many popular blogging systems default to adding <code>rel=nofollow</code> to links added by commenters.</p>

<ul>
<li><a href="http://html5.org/tools/web-apps-tracker?from=340&amp;to=341">r341</a>: <code>rel=nofollow</code> added to HTML 5</li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=1707&amp;to=1708">r1708</a> added the clause about commercial relationships.</li>
</ul>

<h4>rel=noreferrer</h4>

<p><i>New in HTML 5</i></p>

<p><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#link-type-noreferrer">rel=noreferrer</a> "indicates that the no referrer information is to be leaked when following the link." No browser currently supports this. [<a href="http://wearehugh.com/public/2009/04/rel-noreferrer.html">rel=noreferrer test case</a>]</p>

<ul>
<li><a href="http://html5.org/tools/web-apps-tracker?from=1118&amp;to=1119">r1119</a>: <code>rel=noreferrer</code> added to HTML 5</li>
<li><a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-January/005483.html">no referer attrribute for &lt;a&gt;, same reason as ping</a> - initial discussion of a mechanism for blocking referrer information on individual links</li>
<li><a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2007-November/013021.html">several messages about a way to disable referer headers for links</a></li>
<li>"<a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2007-November/013071.html">I don't think that spelling the attribute "noreferer" is consistent. It should be "noreferrer".</a>"</li>
<li>"<a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2007-November/013072.html">I'll switch to [no]referrer.</a>"</li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=1949&amp;to=1950">r1950</a> extends <code>rel=noreferrer</code> to also blow away the 'opener' when used with target=_blank</li>
</ul>

<h4>rel=pingback</h4>

<p><i>New in HTML 5</i></p>

<p><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#link-type-pingback">rel=pingback</a> specifies the address of a "pingback" server. As explained in <a href="http://hixie.ch/specs/pingback/pingback-1.0">the Pingback specification</a>, "The pingback system is a way for a blog to be automatically notified when other Web sites link to it. ... It enables reverse linking -- a way of going back up a chain of links rather than merely drilling down."</p>

<p>Blogging systems, notably WordPress, implement the pingback mechanism to notify authors that you have linked to them when creating a new blog post.</p>

<ul>
<li><a href="http://html5.org/tools/web-apps-tracker?from=342&amp;to=343">r343</a>: <code>rel=pingback</code> added to HTML 5</li>
<li><a href="http://hixie.ch/specs/pingback/pingback-1.0">Pingback 1.0 specification</a></li>
<li><a href="http://www.optiniche.com/blog/117/wordpress-trackback-tutorial/">WordPress Trackback Tutorial</a></li>
</ul>

<h4>rel=prefetch</h4>

<p><i>New in HTML 5</i></p>

<p><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#link-type-prefetch">rel=prefetch</a> "indicates that preemptively fetching and caching the specified resource is likely to be beneficial, as it is highly likely that the user will require this resource." Search engines sometimes add <code>&lt;link rel=prefetch href="<i>URL of top search result</i>"&gt;</code> to the search results page if they feel that the top result is wildly more popular than any other. For example: using Firefox, <a href="http://www.google.com/search?q=cnn">search Google for CNN</a>; view source; search for the keyword "prefetch".</p>

<p>Mozilla Firefox is the only current browser that supports <code>rel=prefetch</code>.</p>

<ul>
<li><a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2004-June/000190.html">What improves Web applications?</a> "A big plus point would be to prefetch the next page so it loads immediately the 'next' button is clicked."</li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=344&amp;to=345">r345</a>: <code>rel=prefetch</code> added to HTML 5</li>
<li><a href="https://developer.mozilla.org/En/Link_prefetching_FAQ">Link prefetching FAQ</a> on Mozilla Developer Center</li>
<li><a href="http://browserspy.dk/prefetch.php">test whether your browser supports <code>rel=prefetch</code></a></li>
</ul>

<h4>rel=search</h4>

<p><i>New in HTML 5</i></p>

<p><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#link-type-search">rel=search</a> "indicates that the referenced document provides an interface specifically for searching the document and its related resources." Specifically, if you want <code>rel=search</code> to do anything useful, it should point to an <a href="http://www.opensearch.org/">OpenSearch</a> document that describes how a browser could construct a URL to search the current site for a given keyword.</p>

<p>OpenSearch (and <code>rel=search</code> links that point to OpenSearch description documents) is supported in Microsoft Internet Explorer since version 7 and Mozilla Firefox since version 2.</p>

<ul>
<li><a href="http://www.opensearch.org/Specifications/OpenSearch/1.1#Autodiscovery_in_HTML.2FXHTML">OpenSearch: Autodiscovery in HTML/XHTML</a></li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=344&amp;to=345">r345</a>: <code>rel=search</code> added to HTML 5</li>
<li><a href="https://developer.mozilla.org/en/Creating_OpenSearch_plugins_for_Firefox">Creating OpenSearch plugins for Firefox</a></li>
<li><a href="https://addons.mozilla.org/en-US/firefox/browse/type:4/cat:all?show=20&amp;sort=popular">Available search plugins for Firefox</a></li>
<li><a href="http://www.microsoft.com/windows/ie/searchguide/en-en/default.mspx">Search Providers for Microsoft Internet Explorer</a></li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=483&amp;to=484">r484</a> adds a note about OpenSearch documents in particular</li>
</ul>

<h4>rel=sidebar</h4>

<p><i>New in HTML 5</i></p>

<p><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#link-type-sidebar">rel=sidebar</a> "indicates that the referenced document, if retrieved, is intended to be shown in a secondary browsing context (if possible), instead of in the current browsing context." What does that mean? In Opera and Mozilla Firefox, it means "when I click this link, prompt the user to create a bookmark that, when selected from the Bookmarks menu, opens the linked document in a browser sidebar." (Opera actually calls it the "panel" instead of the "sidebar.")</p>

<p>Internet Explorer, Safari, and Chrome ignore <code>rel=sidebar</code> and just treat it as a regular link. [<a href="http://wearehugh.com/public/2009/04/rel-sidebar.html">rel=sidebar test case</a>]</p>

<ul>
<li><a href="http://html5.org/tools/web-apps-tracker?from=345&amp;to=346">r346</a>: <code>rel=sidebar</code> added to HTML 5</li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=667&amp;to=668">r668</a> revamps the definition based on the concept of a "secondary browsing context."</li>
</ul>

<h4>rel=tag</h4>

<p><i>New in HTML 5</i></p>

<p><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#link-type-tag">rel=tag</a> "indicates that the tag that the referenced document represents applies to the current document." Marking up "tags" (category keywords) with the <code>rel</code> attribute was <a href="http://www.powazek.com/2005/07/000532.html">invented by Technorati</a> to help them categorize blog posts. Early blogs and tutorials thus referred to them as "Technorati tags." (You read that right: a commercial company convinced the entire world to add metadata that made the company's job easier. Nice work if you can get it!) The syntax was later <a href="http://microformats.org/wiki/rel-tag">standardized within the microformats community</a>, where it was simply called "rel=tag".</p>

<p>Most blogging systems that allow associating categories, keywords, or tags with individual posts will mark them up with <code>rel=tag</code> links. Browsers do not do anything special with them, but they're really designed for search engines to use as a signal of what the page is about.</p>

<ul>
<li><a href="http://microformats.org/wiki/rel-tag">rel-tag microformat specification</a></li>
<li><a href="http://microformats.org/wiki/rel-tag-faq">rel-tag FAQ</a></li>
<li><a href="http://html5.org/tools/web-apps-tracker?from=345&amp;to=346">r346</a>: <code>rel=tag</code> added to HTML 5</li>
</ul>

<h4><del>rel=contact</del></h4>

<p><code>rel=contact</code> was briefly part of HTML 5, but <a href="http://html5.org/tools/web-apps-tracker?from=1710&amp;to=1711">r1711</a> removed it because it conflicted with the same-named <a href="http://gmpg.org/xfn/">XFN relationship</a>.</p>

<h3>Extending rel even further</h3>

<p>There seems to be an infinite supply of ideas for new link relations. In an attempt to prevent people from <a href="http://developer.apple.com/safari/library/documentation/AppleApplications/Reference/SafariWebContent/ConfiguringWebApplications/chapter_8_section_2.html">just making shit up</a>, the WHATWG <a href="http://wiki.whatwg.org/wiki/RelExtensions">maintains a registry of proposed <code>rel</code> values</a> and <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#other-link-types">defines the process for getting them accepted</a>.</p>
<p></p><p>This item was originally posted at: <a href='http://blog.whatwg.org'>http://blog.whatwg.org</a> and is licensed under the <a href='http://www.opensource.org/licenses/mit-license.php'>MIT license</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.htmlfive.net/the-road-to-html-5-link-relations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&lt;section&gt; is not just a &#8220;semantic &lt;div&gt;&#8221;</title>
		<link>http://www.htmlfive.net/section-is-not-just-a-semantic-div/</link>
		<comments>http://www.htmlfive.net/section-is-not-just-a-semantic-div/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 12:28:36 +0000</pubDate>
		<dc:creator>James Graham</dc:creator>
				<category><![CDATA[Elements]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://blog.whatwg.org/?p=604</guid>
		<description><![CDATA[<p>HTML 5 introduces new elements like &#60;section&#62;, &#60;article&#62; and &#60;footer&#62; for structuring the content in your webpages. They can be employed in many situations where &#60;div&#62; is used today and should help you make more readable, maintainable, HTML source. But if you just go through your document and blindly replace all the &#60;div&#62;s with &#60;section&#62;s <em>you are doing it wrong</em>.

</p><p>This is not just semantic nit-picking, there is a practical reason to use these elements correctly. 

</p><p>In HTML 5, there is an algorithm for constructing an outline view of documents. This can be used, for example by AT, to help a user navigate through a document. And &#60;section&#62; and friends are an important part of this algorithm. Each time you nest a &#60;section&#62;, you increase the outline depth by 1 (in case you are wondering what the advantages of this model are compared to the traditional &#60;h1&#62;-&#60;h6&#62; model, consider a web based feedreader that wants to integrate the document structure of the syndicated content with that of the surrounding site. In HTML 4 this means parsing all the content and renumbering all the headings. In HTML5 the headings end up at the right depth for free). So a document like the following:

<pre><code>
&#60;body&#62;
  &#60;h1&#62;This is the main header&#60;/h1&#62;
  &#60;section&#62;
    &#60;h1&#62;This is a subheader&#60;/h1&#62;
    &#60;section&#62;
      &#60;h1&#62;This is a subsubheader&#60;/h1&#62;
    &#60;/section&#62;
  &#60;/section&#62;
  &#60;section&#62;
    &#60;h1&#62;This is a second subheader&#60;/h1&#62;
  &#60;/section&#62;
&#60;/body&#62;
</code>
</pre>

</p><p>has an outline like:

<pre>
This is the main header
+--This is a subheader
    +--This is a subsubheader
+--This is a second subheader
</pre>

</p><p>If you just blindly convert all the &#60;div&#62;s on your pages to &#60;sections&#62; it's pretty unlikely your page will have the outline you expected. And, apart from being a semantic faux-pas, this will confuse the hell out of people who rely on headings for navigation. 

</p><p>Hopefully, in time, we will get tools that make this kind of mistake obvious and CSS support for selecting headings based on depth. Until then remember <i>&#60;section&#62; is not just a semantic &#60;div&#62;</i>

</p>]]></description>
			<content:encoded><![CDATA[<p>HTML 5 introduces new elements like &lt;section&gt;, &lt;article&gt; and &lt;footer&gt; for structuring the content in your webpages. They can be employed in many situations where &lt;div&gt; is used today and should help you make more readable, maintainable, HTML source. But if you just go through your document and blindly replace all the &lt;div&gt;s with &lt;section&gt;s <em>you are doing it wrong</em>.

</p><p>This is not just semantic nit-picking, there is a practical reason to use these elements correctly. 

</p><p>In HTML 5, there is an algorithm for constructing an outline view of documents. This can be used, for example by AT, to help a user navigate through a document. And &lt;section&gt; and friends are an important part of this algorithm. Each time you nest a &lt;section&gt;, you increase the outline depth by 1 (in case you are wondering what the advantages of this model are compared to the traditional &lt;h1&gt;-&lt;h6&gt; model, consider a web based feedreader that wants to integrate the document structure of the syndicated content with that of the surrounding site. In HTML 4 this means parsing all the content and renumbering all the headings. In HTML5 the headings end up at the right depth for free). So a document like the following:

<pre><code>
&lt;body&gt;
  &lt;h1&gt;This is the main header&lt;/h1&gt;
  &lt;section&gt;
    &lt;h1&gt;This is a subheader&lt;/h1&gt;
    &lt;section&gt;
      &lt;h1&gt;This is a subsubheader&lt;/h1&gt;
    &lt;/section&gt;
  &lt;/section&gt;
  &lt;section&gt;
    &lt;h1&gt;This is a second subheader&lt;/h1&gt;
  &lt;/section&gt;
&lt;/body&gt;
</code>
</pre>

</p><p>has an outline like:

<pre>
This is the main header
+--This is a subheader
    +--This is a subsubheader
+--This is a second subheader
</pre>

</p><p>If you just blindly convert all the &lt;div&gt;s on your pages to &lt;sections&gt; it's pretty unlikely your page will have the outline you expected. And, apart from being a semantic faux-pas, this will confuse the hell out of people who rely on headings for navigation. 

</p><p>Hopefully, in time, we will get tools that make this kind of mistake obvious and CSS support for selecting headings based on depth. Until then remember <i>&lt;section&gt; is not just a semantic &lt;div&gt;</i>

</p><p></p><p>This item was originally posted at: <a href='http://blog.whatwg.org'>http://blog.whatwg.org</a> and is licensed under the <a href='http://www.opensource.org/licenses/mit-license.php'>MIT license</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.htmlfive.net/section-is-not-just-a-semantic-div/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Road to HTML 5: contentEditable</title>
		<link>http://www.htmlfive.net/the-road-to-html-5-contenteditable/</link>
		<comments>http://www.htmlfive.net/the-road-to-html-5-contenteditable/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 04:53:24 +0000</pubDate>
		<dc:creator>Mark Pilgrim</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://blog.whatwg.org/?p=577</guid>
		<description><![CDATA[
<p>Welcome back to my semi-regular column, "The Road to HTML 5," where I'll try to explain some of the <a href="http://wiki.whatwg.org/wiki/Differences_from_HTML4">new elements, attributes, and other features</a> in the upcoming HTML 5 specification.</p>

<p>The feature of the day is <code>contentEditable</code>, by which I mean client-side in-browser "rich text" editing. All major browsers support this now, including Firefox 3, Safari 3, Opera 9, Google Chrome, and Internet Explorer (since 5.5). Of course, the devil is in the details.</p>

<p>In this article:</p>

<ul>
<li><a href="#what">What is <code>contentEditable</code>?</a></li>
<li><a href="#how">How does it work?</a></li>
<li><a href="#history">A brief and extremely biased timeline of standardization</a></li>
<li><a href="#conclusion">Conclusion</a></li>
<li><a href="#furtherreading">Further reading</a></li>
</ul>

<h3>What is <code>contentEditable</code>?</h3>

<p>There are really two attributes involved, <code>designMode</code> and <code>contentEditable</code>. The <code>designMode</code> attribute governs the entire document (i.e. it makes the entire document editable, like a dedicated HTML editor). The <code>contentEditable</code> attribute governs just the element on which it appears, and that element's children -- like a rich text editor control within a page. In fact, that was the original use case: enabling web developers to build rich text editors. There are now <a href="http://ajaxian.com/archives/richtexteditors-compared">a variety of such editors available</a> under various licenses.</p>

<p>Both of these attributes, <code>designMode</code> and <code>contentEditable</code>, were originally designed and implemented by Microsoft in Windows Internet Explorer (5.5, to be exact).  There was some superficial documentation on how to use them (so developers could develop rich text editors), but little thought of interoperability. So, no details on all the nitty gritty details of exactly what markup is generated when you press <kbd>ENTER</kbd> <em>right here</em>, or what the <abbr>DOM</abbr> looks like as you backspace your way through a start tag. Much of this sort of information was later reverse-engineered, and cross-browser support for basic operations is actually quite good. (Browsers still vary widely on the details.) The <code>designMode</code> and <code>contentEditable</code> attributes, and the <abbr>API</abbr>s that drive rich text editors, are implemented in all major browsers, including Firefox, Opera, Safari, Google Chrome, and of course Internet Explorer.</p>

<h3>How does it work?</h3>

<p>Mark Finkle wrote <a href="http://starkravingfinkle.org/blog/2007/02/xul-clippings-midas-rich-text-editor/">a nice high-level summary of <code>designMode</code></a>, and later added <a href="http://starkravingfinkle.org/blog/2007/07/firefox-3-contentEditable/">a post about <code>contentEditable</code></a> once it appeared in the Firefox 3 alphas. (That was back in 2007.)  Quoting Mark:</p>

<blockquote>
<p>Mozilla has a rich text editing system (called Midas) and an API similar to Internet Explorer's. Mozilla, like Internet Explorer, supports the ability to make an entire document editable by setting the designMode property of the document object. Once in design mode, the document can be manipulated using various DHTML commands.</p>

<p>... Firefox 3 is expanding its rich WYSIWYG editing capabilities by adding support for the contentEditable attribute. Setting contentEditable to "true" allows you to make parts of a document editable. ...</p>

<p>The API for interacting with the document is:</p>

<dl>
<dt>document.execCommand</dt><dd>Executes the given command.</dd>
<dt>document.queryCommandEnabled</dt><dd>Determines whether the given command can be executed on the document in its current state.</dd>
<dt>document.queryCommandIndeterm</dt><dd>Determines whether the current selection is in an indetermined state.</dd>
<dt>document.queryCommandState</dt><dd>Determines whether the given command has been executed on the current selection.</dd>
<dt>document.queryCommandValue</dt><dd>Determines the current value of the document, range, or current selection for the given command.</dd>
</dl>
</blockquote>

<p>Once you have an editable document (<code>designMode</code>) or element (<code>contentEditable</code>), you use this set of <abbr>API</abbr> calls to issue "commands" on the editable region, and to query the current state of the region. Commands are things like "bold," "italic," "underline," "create a link," "change foreground color," and so on -- all the commands you would expect from a rich text editor. Here's <a href="http://www.quirksmode.org/dom/execCommand/">a test page with 36 commands</a>.</p>

<p>In other words, "supporting the <code>contentEditable</code> attribute" is really just the tip of the iceberg. The real compatibility story is written in the commands which are passed to the <code>document.execCommand()</code> function. So which browsers support which commands?</p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/ms533049(VS.85).aspx">Internet Explorer commands</a></li>
<li><a href="https://developer.mozilla.org/En/Rich-Text_Editing_in_Mozilla">Mozilla Firefox commands</a></li>
<li><a href="http://www.whatwg.org/specs/web-apps/current-work/#command-apis">Command APIs in HTML 5</a></li>
<li><a href="http://www.quirksmode.org/dom/execCommand.html">QuirksMode.org comparison chart</a></li>
</ul>

<p>As you can see from Peter's chart, basic stuff like bold, italic, creating links, and changing colors is well-supported across browsers. After that, the compatibility story gets hairy.</p>

<h3>A brief and extremely biased timeline of standardization</h3>

<p>Reverse-engineering and standardizing <code>contentEditable</code> and its associated <abbr>API</abbr>s was one of the original goals of the WHAT working group, as part of (what at the time was called) "Web Applications 1.0" and is now known as "HTML 5."</p>

<ul>
<li>July 2000. Microsoft releases Internet Explorer 5.5, with support for <code>designMode</code> and <code>contentEditable</code>. Other than some <a href="http://msdn.microsoft.com/en-us/library/ms537837(VS.85).aspx">sparse documentation on MSDN</a>, no further details were given.</li>
<li>November 2004. Ian Hickson: <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2004-November/002313.html">[whatwg] Re: several messages</a>. "One set of the ideas that was brought up in this forum was the ability to extend &#60;textarea&#62; to support syntax highlighting, or WYSIWYG editing of BB code markup, or just the ability to do rich text editing of any kind. Having considered all the suggestions, the only thing I could really see as being realistic would be to do something similar to (and ideally compatible with) IE's 'contentEditable' and 'designMode' attributes."</li>
<li>April 2005. Olav Junker Kjær: "<a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2005-April/003701.html">I have been thinking about HTML editing, which I think is a critical feature</a>."</li>
<li>July 2005. Anne van Kesteren: <a href="http://annevankesteren.nl/2005/07/more-contentEditable">begins to reverse-engineer Microsoft's <code>contentEditable</code> implementation</a>.</li>
<li>July 2005. Anne van Kesteren: <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2005-July/thread.html#4323">[whatwg] [html5] contenteditable specification</a>. The first message points to <a href="http://annevankesteren.nl/projects/whatwg/spec">annevankesteren.nl/projects/whatwg/spec</a>, while (somewhat surprisingly) still exists. An unfinished but fascinating piece of reverse engineering. (Most of this is now merged into the HTML 5 spec, in the <a href="http://www.whatwg.org/specs/web-apps/current-work/#command-apis">Command APIs section</a>.)</li>
<li>July 2005. Anne van Kesteren: <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2005-July/004423.html">[whatwg] [html5] contenteditable specification (again)</a></li>
<li>July 2005. Matthew Raymond: <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2005-July/thread.html#4474">[whatwg] [WF2] Readonly and default pseudoclass matching</a>. Discussion of how <code>contentEditable</code> interacts with proposed (<a href="http://blog.whatwg.org/this-week-day-in-html-5-episode-22">and now standardized</a>) pseudo-classes like <code>:read-only</code>.</li>
<li>August 2005. dolphinling: <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2005-August/thread.html#4526">[whatwg] What exactly is contentEditable for?</a>. Other than the obvious answer, "rich text editing," the discussion focused on how modified content is/could be/should be submitted to the server, and whether it could be implemented without scripting.</li>
<li>September 2005. Ian Hickson: <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2005-September/004660.html">[whatwg] Status update</a>. "Web Apps 1, a.k.a. 'HTML5'. Still very much work in progress. ... The main things that need fleshing out are: (1) contentEditable: at least to a state comparable to WinIE, although we might want to add some of the new features being requested on this list like declarative association with a form."</li>
<li>September 2005. Matthew Raymond: <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2005-September/004795.html">[whatwg] Re: Simple template-based editing</a>. Discussion of a (never-implemented) <code>&#60;htmlarea&#62;</code> element.</li>
<li>June 2006. Lachlan Hunt: <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-June/thread.html#6770">[whatwg] Spellchecking proposal #2</a>. Discussion of how <code>contentEditable</code> interacts with <a href="http://blog.whatwg.org/the-road-to-html-5-spellchecking">the <code>spellcheck</code> attribute</a>. See also: <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-June/006849.html">Ian Hickson's feedback, with examples</a>.</li>
<li>July 2006. Anne van Kesteren: <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-July/thread.html#6902">[whatwg] contenteditable="" needs fixing</a>. (This later led to <a href="http://tc.labs.opera.com/html/global-attributes/contenteditable/">these test cases</a>.)</li>
<li>January 2007. Simon Pieters: <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2007-January/thread.html#9015">[whatwg] contenteditable, &#60;em&#62; and &#60;strong&#62;</a></li>
<li>January 2007. Anne van Kesteren: <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2007-January/thread.html#9131">[whatwg] contenteditable="" values and isContentEditable</a></li>
<li>February 2007. Ian Hickson: "<a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2007-February/009464.html">I have added it to the now-written designMode section</a>."</li>
<li>April 2007. David Hyatt: "<a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2007-April/011061.html">The use case of being able to drop images into a contenteditable region and have them show up as &#60;img /&#62; elements at the appropriate place and then get automatically uploaded somewhere is a really compelling one</a>." See also: <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2007-April/011061.html">Ian Hickson's feedback, 19 months later</a>.</li>
<li>November 2008. Ian Hickson: "<a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2008-November/017596.html">contentEditable is being made more consistent, but there's still no non-scripted solution, since nobody can agree on what elements to allow</a>."</li>
<li>December 2008. Ian Hickson: <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2008-December/thread.html#17679">[whatwg] &#60;input placeholder=""&#62;</a>. Discussion of whether <a href="http://www.whatwg.org/specs/web-apps/current-work/#the-placeholder-attribute">the <code>placeholder</code> attribute</a> should also apply to <code>contentEditable</code> regions and <code>designMode</code> documents in an <code>&#60;iframe&#62;</code>.</li>
</ul>

<h3>Conclusion</h3>

<p>The original use case for <code>contentEditable</code> -- building rich text editors -- is alive and well on the web. Cross-browser compatibility can be charitably described as "evolving," but we are long past the point where "only IE can do that fancy rich-text stuff." Standardization through the <abbr>WHATWG</abbr> has shaken out numerous interoperability bugs and led to thoughtful consideration of a wide variety of edge cases. Most of these benefits had to be realized through reverse engineering, rather than cooperation, but the work has been done and the web is better for it.</p>

<h3>Further reading</h3>

<ul>
<li><a href="http://valums.com/edit-in-place/">Edit-in-place with contentEditable property</a>. Up-to-date, cross-browser.</li>
<li><a href="http://dev.opera.com/articles/view/rich-html-editing-in-the-browser-part-1/">Rich HTML editing in the browser: part 1</a>. A basic tutorial. Up-to-date, cross-browser.</li>
<li><a href="http://dev.opera.com/articles/view/rich-html-editing-in-the-browser-part-2/">Rich HTML editing in the browser: part 2</a>. More advanced. Up-to-date, cross-browser.</li>
<li><a href="http://niichavo.wordpress.com/2009/01/06/contentEditable-div-cursor-position/">Finding cursor position in a contentEditable div</a>. Up-to-date, cross-browser.</li>
<li><a href="http://msdn.microsoft.com/en-us/library/ms537837(VS.85).aspx">contentEditable attribute on MSDN</a> partially documents Internet Explorer's implementation. A bit out of date (see comments). Microsoft-only.</li>
<li><a href="http://tc.labs.opera.com/html/global-attributes/contentEditable/">Opera's test cases for <code>contentEditable</code> attribute values</a>.</li>
<li><a href="http://www.quirksmode.org/dom/execCommand.html"><code>execCommand</code> compatibility</a>. A bit out of date. Covers older browsers only, no public betas, no Firefox 3, no Google Chrome.</li>
<li><a href="http://ajaxian.com/archives/richtexteditors-compared">The bane and choice of Rich Text Editors</a>.</li>
</ul>
]]></description>
			<content:encoded><![CDATA[
<p>Welcome back to my semi-regular column, "The Road to HTML 5," where I'll try to explain some of the <a href="http://wiki.whatwg.org/wiki/Differences_from_HTML4">new elements, attributes, and other features</a> in the upcoming HTML 5 specification.</p>

<p>The feature of the day is <code>contentEditable</code>, by which I mean client-side in-browser "rich text" editing. All major browsers support this now, including Firefox 3, Safari 3, Opera 9, Google Chrome, and Internet Explorer (since 5.5). Of course, the devil is in the details.</p>

<p>In this article:</p>

<ul>
<li><a href="#what">What is <code>contentEditable</code>?</a></li>
<li><a href="#how">How does it work?</a></li>
<li><a href="#history">A brief and extremely biased timeline of standardization</a></li>
<li><a href="#conclusion">Conclusion</a></li>
<li><a href="#furtherreading">Further reading</a></li>
</ul>

<h3>What is <code>contentEditable</code>?</h3>

<p>There are really two attributes involved, <code>designMode</code> and <code>contentEditable</code>. The <code>designMode</code> attribute governs the entire document (i.e. it makes the entire document editable, like a dedicated HTML editor). The <code>contentEditable</code> attribute governs just the element on which it appears, and that element's children -- like a rich text editor control within a page. In fact, that was the original use case: enabling web developers to build rich text editors. There are now <a href="http://ajaxian.com/archives/richtexteditors-compared">a variety of such editors available</a> under various licenses.</p>

<p>Both of these attributes, <code>designMode</code> and <code>contentEditable</code>, were originally designed and implemented by Microsoft in Windows Internet Explorer (5.5, to be exact).  There was some superficial documentation on how to use them (so developers could develop rich text editors), but little thought of interoperability. So, no details on all the nitty gritty details of exactly what markup is generated when you press <kbd>ENTER</kbd> <em>right here</em>, or what the <abbr>DOM</abbr> looks like as you backspace your way through a start tag. Much of this sort of information was later reverse-engineered, and cross-browser support for basic operations is actually quite good. (Browsers still vary widely on the details.) The <code>designMode</code> and <code>contentEditable</code> attributes, and the <abbr>API</abbr>s that drive rich text editors, are implemented in all major browsers, including Firefox, Opera, Safari, Google Chrome, and of course Internet Explorer.</p>

<h3>How does it work?</h3>

<p>Mark Finkle wrote <a href="http://starkravingfinkle.org/blog/2007/02/xul-clippings-midas-rich-text-editor/">a nice high-level summary of <code>designMode</code></a>, and later added <a href="http://starkravingfinkle.org/blog/2007/07/firefox-3-contentEditable/">a post about <code>contentEditable</code></a> once it appeared in the Firefox 3 alphas. (That was back in 2007.)  Quoting Mark:</p>

<blockquote>
<p>Mozilla has a rich text editing system (called Midas) and an API similar to Internet Explorer's. Mozilla, like Internet Explorer, supports the ability to make an entire document editable by setting the designMode property of the document object. Once in design mode, the document can be manipulated using various DHTML commands.</p>

<p>... Firefox 3 is expanding its rich WYSIWYG editing capabilities by adding support for the contentEditable attribute. Setting contentEditable to "true" allows you to make parts of a document editable. ...</p>

<p>The API for interacting with the document is:</p>

<dl>
<dt>document.execCommand</dt><dd>Executes the given command.</dd>
<dt>document.queryCommandEnabled</dt><dd>Determines whether the given command can be executed on the document in its current state.</dd>
<dt>document.queryCommandIndeterm</dt><dd>Determines whether the current selection is in an indetermined state.</dd>
<dt>document.queryCommandState</dt><dd>Determines whether the given command has been executed on the current selection.</dd>
<dt>document.queryCommandValue</dt><dd>Determines the current value of the document, range, or current selection for the given command.</dd>
</dl>
</blockquote>

<p>Once you have an editable document (<code>designMode</code>) or element (<code>contentEditable</code>), you use this set of <abbr>API</abbr> calls to issue "commands" on the editable region, and to query the current state of the region. Commands are things like "bold," "italic," "underline," "create a link," "change foreground color," and so on -- all the commands you would expect from a rich text editor. Here's <a href="http://www.quirksmode.org/dom/execCommand/">a test page with 36 commands</a>.</p>

<p>In other words, "supporting the <code>contentEditable</code> attribute" is really just the tip of the iceberg. The real compatibility story is written in the commands which are passed to the <code>document.execCommand()</code> function. So which browsers support which commands?</p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/ms533049(VS.85).aspx">Internet Explorer commands</a></li>
<li><a href="https://developer.mozilla.org/En/Rich-Text_Editing_in_Mozilla">Mozilla Firefox commands</a></li>
<li><a href="http://www.whatwg.org/specs/web-apps/current-work/#command-apis">Command APIs in HTML 5</a></li>
<li><a href="http://www.quirksmode.org/dom/execCommand.html">QuirksMode.org comparison chart</a></li>
</ul>

<p>As you can see from Peter's chart, basic stuff like bold, italic, creating links, and changing colors is well-supported across browsers. After that, the compatibility story gets hairy.</p>

<h3>A brief and extremely biased timeline of standardization</h3>

<p>Reverse-engineering and standardizing <code>contentEditable</code> and its associated <abbr>API</abbr>s was one of the original goals of the WHAT working group, as part of (what at the time was called) "Web Applications 1.0" and is now known as "HTML 5."</p>

<ul>
<li>July 2000. Microsoft releases Internet Explorer 5.5, with support for <code>designMode</code> and <code>contentEditable</code>. Other than some <a href="http://msdn.microsoft.com/en-us/library/ms537837(VS.85).aspx">sparse documentation on MSDN</a>, no further details were given.</li>
<li>November 2004. Ian Hickson: <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2004-November/002313.html">[whatwg] Re: several messages</a>. "One set of the ideas that was brought up in this forum was the ability to extend &lt;textarea&gt; to support syntax highlighting, or WYSIWYG editing of BB code markup, or just the ability to do rich text editing of any kind. Having considered all the suggestions, the only thing I could really see as being realistic would be to do something similar to (and ideally compatible with) IE's 'contentEditable' and 'designMode' attributes."</li>
<li>April 2005. Olav Junker Kjær: "<a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2005-April/003701.html">I have been thinking about HTML editing, which I think is a critical feature</a>."</li>
<li>July 2005. Anne van Kesteren: <a href="http://annevankesteren.nl/2005/07/more-contentEditable">begins to reverse-engineer Microsoft's <code>contentEditable</code> implementation</a>.</li>
<li>July 2005. Anne van Kesteren: <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2005-July/thread.html#4323">[whatwg] [html5] contenteditable specification</a>. The first message points to <a href="http://annevankesteren.nl/projects/whatwg/spec">annevankesteren.nl/projects/whatwg/spec</a>, while (somewhat surprisingly) still exists. An unfinished but fascinating piece of reverse engineering. (Most of this is now merged into the HTML 5 spec, in the <a href="http://www.whatwg.org/specs/web-apps/current-work/#command-apis">Command APIs section</a>.)</li>
<li>July 2005. Anne van Kesteren: <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2005-July/004423.html">[whatwg] [html5] contenteditable specification (again)</a></li>
<li>July 2005. Matthew Raymond: <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2005-July/thread.html#4474">[whatwg] [WF2] Readonly and default pseudoclass matching</a>. Discussion of how <code>contentEditable</code> interacts with proposed (<a href="http://blog.whatwg.org/this-week-day-in-html-5-episode-22">and now standardized</a>) pseudo-classes like <code>:read-only</code>.</li>
<li>August 2005. dolphinling: <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2005-August/thread.html#4526">[whatwg] What exactly is contentEditable for?</a>. Other than the obvious answer, "rich text editing," the discussion focused on how modified content is/could be/should be submitted to the server, and whether it could be implemented without scripting.</li>
<li>September 2005. Ian Hickson: <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2005-September/004660.html">[whatwg] Status update</a>. "Web Apps 1, a.k.a. 'HTML5'. Still very much work in progress. ... The main things that need fleshing out are: (1) contentEditable: at least to a state comparable to WinIE, although we might want to add some of the new features being requested on this list like declarative association with a form."</li>
<li>September 2005. Matthew Raymond: <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2005-September/004795.html">[whatwg] Re: Simple template-based editing</a>. Discussion of a (never-implemented) <code>&lt;htmlarea&gt;</code> element.</li>
<li>June 2006. Lachlan Hunt: <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-June/thread.html#6770">[whatwg] Spellchecking proposal #2</a>. Discussion of how <code>contentEditable</code> interacts with <a href="http://blog.whatwg.org/the-road-to-html-5-spellchecking">the <code>spellcheck</code> attribute</a>. See also: <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-June/006849.html">Ian Hickson's feedback, with examples</a>.</li>
<li>July 2006. Anne van Kesteren: <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-July/thread.html#6902">[whatwg] contenteditable="" needs fixing</a>. (This later led to <a href="http://tc.labs.opera.com/html/global-attributes/contenteditable/">these test cases</a>.)</li>
<li>January 2007. Simon Pieters: <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2007-January/thread.html#9015">[whatwg] contenteditable, &lt;em&gt; and &lt;strong&gt;</a></li>
<li>January 2007. Anne van Kesteren: <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2007-January/thread.html#9131">[whatwg] contenteditable="" values and isContentEditable</a></li>
<li>February 2007. Ian Hickson: "<a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2007-February/009464.html">I have added it to the now-written designMode section</a>."</li>
<li>April 2007. David Hyatt: "<a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2007-April/011061.html">The use case of being able to drop images into a contenteditable region and have them show up as &lt;img /&gt; elements at the appropriate place and then get automatically uploaded somewhere is a really compelling one</a>." See also: <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2007-April/011061.html">Ian Hickson's feedback, 19 months later</a>.</li>
<li>November 2008. Ian Hickson: "<a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2008-November/017596.html">contentEditable is being made more consistent, but there's still no non-scripted solution, since nobody can agree on what elements to allow</a>."</li>
<li>December 2008. Ian Hickson: <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2008-December/thread.html#17679">[whatwg] &lt;input placeholder=""&gt;</a>. Discussion of whether <a href="http://www.whatwg.org/specs/web-apps/current-work/#the-placeholder-attribute">the <code>placeholder</code> attribute</a> should also apply to <code>contentEditable</code> regions and <code>designMode</code> documents in an <code>&lt;iframe&gt;</code>.</li>
</ul>

<h3>Conclusion</h3>

<p>The original use case for <code>contentEditable</code> -- building rich text editors -- is alive and well on the web. Cross-browser compatibility can be charitably described as "evolving," but we are long past the point where "only IE can do that fancy rich-text stuff." Standardization through the <abbr>WHATWG</abbr> has shaken out numerous interoperability bugs and led to thoughtful consideration of a wide variety of edge cases. Most of these benefits had to be realized through reverse engineering, rather than cooperation, but the work has been done and the web is better for it.</p>

<h3>Further reading</h3>

<ul>
<li><a href="http://valums.com/edit-in-place/">Edit-in-place with contentEditable property</a>. Up-to-date, cross-browser.</li>
<li><a href="http://dev.opera.com/articles/view/rich-html-editing-in-the-browser-part-1/">Rich HTML editing in the browser: part 1</a>. A basic tutorial. Up-to-date, cross-browser.</li>
<li><a href="http://dev.opera.com/articles/view/rich-html-editing-in-the-browser-part-2/">Rich HTML editing in the browser: part 2</a>. More advanced. Up-to-date, cross-browser.</li>
<li><a href="http://niichavo.wordpress.com/2009/01/06/contentEditable-div-cursor-position/">Finding cursor position in a contentEditable div</a>. Up-to-date, cross-browser.</li>
<li><a href="http://msdn.microsoft.com/en-us/library/ms537837(VS.85).aspx">contentEditable attribute on MSDN</a> partially documents Internet Explorer's implementation. A bit out of date (see comments). Microsoft-only.</li>
<li><a href="http://tc.labs.opera.com/html/global-attributes/contentEditable/">Opera's test cases for <code>contentEditable</code> attribute values</a>.</li>
<li><a href="http://www.quirksmode.org/dom/execCommand.html"><code>execCommand</code> compatibility</a>. A bit out of date. Covers older browsers only, no public betas, no Firefox 3, no Google Chrome.</li>
<li><a href="http://ajaxian.com/archives/richtexteditors-compared">The bane and choice of Rich Text Editors</a>.</li>
</ul>
<p></p><p>This item was originally posted at: <a href='http://blog.whatwg.org'>http://blog.whatwg.org</a> and is licensed under the <a href='http://www.opensource.org/licenses/mit-license.php'>MIT license</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.htmlfive.net/the-road-to-html-5-contenteditable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Road to HTML 5: spellchecking</title>
		<link>http://www.htmlfive.net/the-road-to-html-5-spellchecking/</link>
		<comments>http://www.htmlfive.net/the-road-to-html-5-spellchecking/#comments</comments>
		<pubDate>Wed, 04 Mar 2009 22:51:02 +0000</pubDate>
		<dc:creator>Mark Pilgrim</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://blog.whatwg.org/?p=565</guid>
		<description><![CDATA[<p>Welcome back to my semi-regular column, "The Road to HTML 5," where I'll try to explain some of the <a href="http://wiki.whatwg.org/wiki/Differences_from_HTML4">new elements, attributes, and other features</a> in the upcoming HTML 5 specification.</p>

<p>The feature of the day is spell checking, by which I mean client-side in-browser checking of text in standard <code>&#60;textarea&#62;</code> and <code>&#60;input type=text&#62;</code> elements. Several browsers support this out-of-the-box, including Firefox 2 and 3, Safari 3, Opera 9, and Google Chrome. However, each browser has different defaults of which elements get spell-checked, and only a handful allow the web author to suggest whether browsers should offer checking on a particular element.</p>

<p>In this article:</p>

<ul>
<li><a href="#history">A brief history of the <code>spellcheck</code> attribute</a></li>
<li><a href="#examples">Examples</a></li>
<li><a href="#compatibility">Browser support</a></li>
<li><a href="#detection">Detecting support for the <code>spellcheck</code> attribute</a></li>
<li><a href="#conclusion">Conclusion</a></li>
</ul>

<h3>A brief history of the <code>spellcheck</code> attribute</h3>

<p>That last bit, by the way, is why this is relevant to HTML 5. Browser features are interesting, but are mostly outside the purview of spec-land. But the idea of a markup hint to suggest turning spell-checking on or off has been bounced around for years.  To wit:</p>

<ul>
<li>May 2006: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=339127">Mozilla bug 339127 - Provide a way for a web page to enable/disable spell checking on a given field</a>. Brett Wilson <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=339127#c2">outlines the thinking, and a potential algorithm</a>, for using the <code>accept</code> attribute to trigger spell-checking.</li>
<li>May 2006: Ian Hickson mentions <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-May/006476.html">&#60;input type="text" accept=""&#62;</a> on the WHATWG mailing list, triggering <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-May/thread.html#6476">a long discussion</a> (<a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-June/thread.html#6591">continued in June archives</a>). This discussion resulted in...</li>
<li>June 2006: <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-June/006762.html">Spellchecking proposal #2</a>, which argued against the more-general <code>accept</code> attribute and in favor of a more-specific <code>spellcheck</code> attribute. <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-June/thread.html#6762">More discussion ensued</a>, which led to...</li>
<li>June 2006: <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-June/006849.html">Spellchecking mark III</a>, which, unsurprisingly, <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-June/thread.html#6849">led to even more discussion</a>, but no resolution.</li>
<li>December 2008: "<a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2008-December/018003.html">the [spellcheck] attribute has seen very little interest outside of Google ... I have therefore not added this feature to HTML5 for the time being. If there is more interest in this feature, please speak up." Anne van Kesteren (Opera) immediately replied, "</a><a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2008-December/018004.html">Opera wants to support this feature as well in due course</a>." Maciej Stachowiak (Apple) stated, "WebKit by default spellchecks (and grammar checks) all editable parts of the document, and it is not obvious to me why one would want to force it off for particular form controls or editable HTML areas." <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2008-December/thread.html#18003">More vigorous discussion</a> (<a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2009-January/thread.html#18041">continued in January 2009 archives</a>).</li>
<li>February 2009: Ian Hickson announces, "<a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2009-February/018509.html">I have added spellcheck="" to the spec</a>." <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2009-February/thread.html#18509">Followups mostly focus on what the attribute should be called, and what values it should take</a>. (More on this in a minute.)</li>
<li>February 26, 2009: "<a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2009-February/018664.html">Based on the interest (not uniform interest, but interest nonetheless) on this topic, I've left the feature in the spec</a>." Yeah, February 29th -- that was last week. So don't in any way consider this the final word on the subject.</li>
</ul>

<h3>Examples</h3>

<p>Getting down to the technical details, the <code>spellcheck</code> attribute is a bit of an oddball. Most boolean attributes (such as <code>&#60;option selected&#62;</code>) are false if they are absent, true if they are present, and true if they are present with a value the same as the attribute name (e.g. <code>&#60;option selected=selected&#62;</code>). The <code>spellcheck</code> attribute is not like that; instead, it requires an attribute value of either <code>true</code> or <code>false</code>.</p>

<p>So this is valid:</p>

<blockquote><pre><code>&#60;textarea spellcheck="true"&#62;</code></pre></blockquote>

<p>And this is valid:</p>

<blockquote><pre><code>&#60;textarea spellcheck="false"&#62;</code></pre></blockquote>

<p>But this is not valid:</p>

<blockquote><pre><code><s>&#60;textarea spellcheck&#62;</s></code></pre></blockquote>

<h3>Browser support</h3>

<p>Browser support is currently... limited.</p>

<table border="1">
<tr><th>Markup</th><th>Firefox 3.0.6</th><th>Google Chrome 1.0.154.48</th><th>Safari 3.2.1</th><th>Opera 9.62</th></tr>
<tr><th><code>&#60;input type=text&#62;</code></th><td>offer on right-click</td><td>no check</td><td>check as you type</td><td>offer on right-click</td>
</tr><tr><th><code>&#60;input type=text spellcheck=true&#62;</code></th><td>check as you type</td><td>no check</td><td>check as you type</td><td>offer on right-click</td>
</tr><tr><th><code>&#60;input type=text spellcheck=false&#62;</code></th><td>offer on right-click</td><td>no check</td><td>check as you type</td><td>offer on right-click</td>
</tr><tr><th><code>&#60;input type=text spellcheck&#62;</code> <b>invalid</b></th><td>offer on right-click</td><td>no check</td><td>check as you type</td><td>offer on right-click</td>
</tr><tr><th><code>&#60;input type=text spellcheck=spellcheck&#62;</code> <b>invalid</b></th><td>offer on right-click</td><td>no check</td><td>check as you type</td><td>offer on right-click</td>
</tr><tr><th><code>&#60;input type=text spellcheck=on&#62;</code> <b>invalid</b></th><td>offer on right-click</td><td>no check</td><td>check as you type</td><td>offer on right-click</td>
</tr><tr><th><code>&#60;input type=text spellcheck=off&#62;</code> <b>invalid</b></th><td>offer on right-click</td><td>no check</td><td>check as you type</td><td>offer on right-click</td>
</tr><tr><th><code>&#60;textarea&#62;</code></th><td>check as you type</td><td>check as you type</td><td>check as you type</td><td>offer on right-click</td></tr>
<tr><th><code>&#60;textarea spellcheck=true&#62;</code></th><td>check as you type</td><td>check as you type</td><td>check as you type</td><td>offer on right-click</td></tr>
<tr><th><code>&#60;textarea spellcheck=false&#62;</code></th><td>offer on right-click</td><td>check as you type</td><td>check as you type</td><td>offer on right-click</td></tr>
<tr><th><code>&#60;textarea spellcheck&#62;</code> <b>invalid</b></th><td>check as you type</td><td>check as you type</td><td>check as you type</td><td>offer on right-click</td></tr>
<tr><th><code>&#60;textarea spellcheck=spellcheck&#62;</code> <b>invalid</b></th><td>check as you type</td><td>check as you type</td><td>check as you type</td><td>offer on right-click</td></tr>
<tr><th><code>&#60;textarea spellcheck=on&#62;</code> <b>invalid</b></th><td>check as you type</td><td>check as you type</td><td>check as you type</td><td>offer on right-click</td></tr>
<tr><th><code>&#60;textarea spellcheck=off&#62;</code> <b>invalid</b></th><td>check as you type</td><td>check as you type</td><td>check as you type</td><td>offer on right-click</td></tr>
</table>

<p>In other words:</p>

<ul>
<li>In the absence of the <code>spellcheck</code> attribute, Firefox offers as-you-type spellcheck <code>&#60;textarea&#62;</code> elements but not <code>&#60;input type=text&#62;</code> elements. It treats the <code>spellcheck</code> attribute with a <code>true</code> or <code>false</code> value as a signal to offer as-you-type spellcheck (or turn it off where it defaults to on). All invalid markup variations are ignored, in the sense that they do not change Firefox's per-element-type defaults. It lets the user turn spellcheck on and off on a per-element basis, which overrides both the <code>spellcheck</code> attribute and the browser's per-element-type defaults.</li>
<li>Google Chrome offers as-you-type spellcheck on <code>&#60;textarea&#62;</code> elements but not <code>&#60;input type=text&#62;</code> elements. It ignores the <code>spellcheck</code> attribute entirely. It does not offer the end user the option to change the default behavior or manually check individual fields.</li>
<li>Safari 3 offers as-you-type spellcheck on <code>&#60;textarea&#62;</code> and <code>&#60;input type=text&#62;</code> elements. It ignores the <code>spellcheck</code> attribute entirely. It allows the user to toggle as-you-type spellcheck globally, which immediately affects all elements of all types. It does not offer the end user the option to change the default behavior or manually check individual fields.</li>
<li>Opera 9 offers spellcheck from the context menu on <code>&#60;textarea&#62;</code> and <code>&#60;input type=text&#62;</code> elements. It ignores the <code>spellcheck</code> attribute entirely. It does not offer as-you-type spellcheck.</li>
</ul>

<h3>Detecting support for the <code>spellcheck</code> attribute</h3>

<p>Browsers that support the <code>spellcheck</code> attribute will always reflect the attribute in the <code>.spellcheck</code> property of the element's <abbr>DOM</abbr> node, even if the <code>spellcheck</code> attribute does not appear in the page markup. You can use this to construct a simple test to check whether the browser supports the <code>spellcheck</code> attribute:</p>

<blockquote><pre><code>if ('spellcheck' in document.createElement('textarea')) {
    alert('browser supports spellcheck attribute');
  } else {
    alert('browser does not support spellcheck attribute');
  }</code></pre></blockquote>

<p>This will pop up an alert stating "browser supports spellcheck attribute" in Firefox 2 and 3, or an alert stating "browser does not support spellcheck attribute" in Safari 3, Opera 9, Google Chrome, and Internet Explorer.</p>

<p><em>Note: Internet Explorer will reflect any attribute present in the page markup. If you include a <code>spellcheck</code> attribute on an element and then test whether that element's <abbr>DOM</abbr> node contains a <code>.spellcheck</code> property, IE will always return true. The safest way to check is to create a new element in script, like the example above, instead of testing a pre-existing element on your page.</em></p>

<h3>Conclusion</h3>

<p>You can start using the <code>spellcheck</code> attribute today, but it only affects the behavior of Firefox. However, it has no adverse effects in other browsers. Be sure to use either <code>spellcheck="true"</code> or <code>spellcheck="false"</code>, as these are the only values supported by Firefox (and the only valid values according to the HTML 5 spec as it stands today).</p>
]]></description>
			<content:encoded><![CDATA[<p>Welcome back to my semi-regular column, "The Road to HTML 5," where I'll try to explain some of the <a href="http://wiki.whatwg.org/wiki/Differences_from_HTML4">new elements, attributes, and other features</a> in the upcoming HTML 5 specification.</p>

<p>The feature of the day is spell checking, by which I mean client-side in-browser checking of text in standard <code>&lt;textarea&gt;</code> and <code>&lt;input type=text&gt;</code> elements. Several browsers support this out-of-the-box, including Firefox 2 and 3, Safari 3, Opera 9, and Google Chrome. However, each browser has different defaults of which elements get spell-checked, and only a handful allow the web author to suggest whether browsers should offer checking on a particular element.</p>

<p>In this article:</p>

<ul>
<li><a href="#history">A brief history of the <code>spellcheck</code> attribute</a></li>
<li><a href="#examples">Examples</a></li>
<li><a href="#compatibility">Browser support</a></li>
<li><a href="#detection">Detecting support for the <code>spellcheck</code> attribute</a></li>
<li><a href="#conclusion">Conclusion</a></li>
</ul>

<h3>A brief history of the <code>spellcheck</code> attribute</h3>

<p>That last bit, by the way, is why this is relevant to HTML 5. Browser features are interesting, but are mostly outside the purview of spec-land. But the idea of a markup hint to suggest turning spell-checking on or off has been bounced around for years.  To wit:</p>

<ul>
<li>May 2006: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=339127">Mozilla bug 339127 - Provide a way for a web page to enable/disable spell checking on a given field</a>. Brett Wilson <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=339127#c2">outlines the thinking, and a potential algorithm</a>, for using the <code>accept</code> attribute to trigger spell-checking.</li>
<li>May 2006: Ian Hickson mentions <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-May/006476.html">&lt;input type="text" accept=""&gt;</a> on the WHATWG mailing list, triggering <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-May/thread.html#6476">a long discussion</a> (<a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-June/thread.html#6591">continued in June archives</a>). This discussion resulted in...</li>
<li>June 2006: <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-June/006762.html">Spellchecking proposal #2</a>, which argued against the more-general <code>accept</code> attribute and in favor of a more-specific <code>spellcheck</code> attribute. <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-June/thread.html#6762">More discussion ensued</a>, which led to...</li>
<li>June 2006: <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-June/006849.html">Spellchecking mark III</a>, which, unsurprisingly, <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-June/thread.html#6849">led to even more discussion</a>, but no resolution.</li>
<li>December 2008: "<a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2008-December/018003.html">the [spellcheck] attribute has seen very little interest outside of Google ... I have therefore not added this feature to HTML5 for the time being. If there is more interest in this feature, please speak up." Anne van Kesteren (Opera) immediately replied, "</a><a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2008-December/018004.html">Opera wants to support this feature as well in due course</a>." Maciej Stachowiak (Apple) stated, "WebKit by default spellchecks (and grammar checks) all editable parts of the document, and it is not obvious to me why one would want to force it off for particular form controls or editable HTML areas." <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2008-December/thread.html#18003">More vigorous discussion</a> (<a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2009-January/thread.html#18041">continued in January 2009 archives</a>).</li>
<li>February 2009: Ian Hickson announces, "<a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2009-February/018509.html">I have added spellcheck="" to the spec</a>." <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2009-February/thread.html#18509">Followups mostly focus on what the attribute should be called, and what values it should take</a>. (More on this in a minute.)</li>
<li>February 26, 2009: "<a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2009-February/018664.html">Based on the interest (not uniform interest, but interest nonetheless) on this topic, I've left the feature in the spec</a>." Yeah, February 29th -- that was last week. So don't in any way consider this the final word on the subject.</li>
</ul>

<h3>Examples</h3>

<p>Getting down to the technical details, the <code>spellcheck</code> attribute is a bit of an oddball. Most boolean attributes (such as <code>&lt;option selected&gt;</code>) are false if they are absent, true if they are present, and true if they are present with a value the same as the attribute name (e.g. <code>&lt;option selected=selected&gt;</code>). The <code>spellcheck</code> attribute is not like that; instead, it requires an attribute value of either <code>true</code> or <code>false</code>.</p>

<p>So this is valid:</p>

<blockquote><pre><code>&lt;textarea spellcheck="true"&gt;</code></pre></blockquote>

<p>And this is valid:</p>

<blockquote><pre><code>&lt;textarea spellcheck="false"&gt;</code></pre></blockquote>

<p>But this is not valid:</p>

<blockquote><pre><code><s>&lt;textarea spellcheck&gt;</s></code></pre></blockquote>

<h3>Browser support</h3>

<p>Browser support is currently... limited.</p>

<table border="1">
<tr><th>Markup</th><th>Firefox 3.0.6</th><th>Google Chrome 1.0.154.48</th><th>Safari 3.2.1</th><th>Opera 9.62</th></tr>
<tr><th><code>&lt;input type=text&gt;</code></th><td>offer on right-click</td><td>no check</td><td>check as you type</td><td>offer on right-click</td>
</tr><tr><th><code>&lt;input type=text spellcheck=true&gt;</code></th><td>check as you type</td><td>no check</td><td>check as you type</td><td>offer on right-click</td>
</tr><tr><th><code>&lt;input type=text spellcheck=false&gt;</code></th><td>offer on right-click</td><td>no check</td><td>check as you type</td><td>offer on right-click</td>
</tr><tr><th><code>&lt;input type=text spellcheck&gt;</code> <b>invalid</b></th><td>offer on right-click</td><td>no check</td><td>check as you type</td><td>offer on right-click</td>
</tr><tr><th><code>&lt;input type=text spellcheck=spellcheck&gt;</code> <b>invalid</b></th><td>offer on right-click</td><td>no check</td><td>check as you type</td><td>offer on right-click</td>
</tr><tr><th><code>&lt;input type=text spellcheck=on&gt;</code> <b>invalid</b></th><td>offer on right-click</td><td>no check</td><td>check as you type</td><td>offer on right-click</td>
</tr><tr><th><code>&lt;input type=text spellcheck=off&gt;</code> <b>invalid</b></th><td>offer on right-click</td><td>no check</td><td>check as you type</td><td>offer on right-click</td>
</tr><tr><th><code>&lt;textarea&gt;</code></th><td>check as you type</td><td>check as you type</td><td>check as you type</td><td>offer on right-click</td></tr>
<tr><th><code>&lt;textarea spellcheck=true&gt;</code></th><td>check as you type</td><td>check as you type</td><td>check as you type</td><td>offer on right-click</td></tr>
<tr><th><code>&lt;textarea spellcheck=false&gt;</code></th><td>offer on right-click</td><td>check as you type</td><td>check as you type</td><td>offer on right-click</td></tr>
<tr><th><code>&lt;textarea spellcheck&gt;</code> <b>invalid</b></th><td>check as you type</td><td>check as you type</td><td>check as you type</td><td>offer on right-click</td></tr>
<tr><th><code>&lt;textarea spellcheck=spellcheck&gt;</code> <b>invalid</b></th><td>check as you type</td><td>check as you type</td><td>check as you type</td><td>offer on right-click</td></tr>
<tr><th><code>&lt;textarea spellcheck=on&gt;</code> <b>invalid</b></th><td>check as you type</td><td>check as you type</td><td>check as you type</td><td>offer on right-click</td></tr>
<tr><th><code>&lt;textarea spellcheck=off&gt;</code> <b>invalid</b></th><td>check as you type</td><td>check as you type</td><td>check as you type</td><td>offer on right-click</td></tr>
</table>

<p>In other words:</p>

<ul>
<li>In the absence of the <code>spellcheck</code> attribute, Firefox offers as-you-type spellcheck <code>&lt;textarea&gt;</code> elements but not <code>&lt;input type=text&gt;</code> elements. It treats the <code>spellcheck</code> attribute with a <code>true</code> or <code>false</code> value as a signal to offer as-you-type spellcheck (or turn it off where it defaults to on). All invalid markup variations are ignored, in the sense that they do not change Firefox's per-element-type defaults. It lets the user turn spellcheck on and off on a per-element basis, which overrides both the <code>spellcheck</code> attribute and the browser's per-element-type defaults.</li>
<li>Google Chrome offers as-you-type spellcheck on <code>&lt;textarea&gt;</code> elements but not <code>&lt;input type=text&gt;</code> elements. It ignores the <code>spellcheck</code> attribute entirely. It does not offer the end user the option to change the default behavior or manually check individual fields.</li>
<li>Safari 3 offers as-you-type spellcheck on <code>&lt;textarea&gt;</code> and <code>&lt;input type=text&gt;</code> elements. It ignores the <code>spellcheck</code> attribute entirely. It allows the user to toggle as-you-type spellcheck globally, which immediately affects all elements of all types. It does not offer the end user the option to change the default behavior or manually check individual fields.</li>
<li>Opera 9 offers spellcheck from the context menu on <code>&lt;textarea&gt;</code> and <code>&lt;input type=text&gt;</code> elements. It ignores the <code>spellcheck</code> attribute entirely. It does not offer as-you-type spellcheck.</li>
</ul>

<h3>Detecting support for the <code>spellcheck</code> attribute</h3>

<p>Browsers that support the <code>spellcheck</code> attribute will always reflect the attribute in the <code>.spellcheck</code> property of the element's <abbr>DOM</abbr> node, even if the <code>spellcheck</code> attribute does not appear in the page markup. You can use this to construct a simple test to check whether the browser supports the <code>spellcheck</code> attribute:</p>

<blockquote><pre><code>if ('spellcheck' in document.createElement('textarea')) {
    alert('browser supports spellcheck attribute');
  } else {
    alert('browser does not support spellcheck attribute');
  }</code></pre></blockquote>

<p>This will pop up an alert stating "browser supports spellcheck attribute" in Firefox 2 and 3, or an alert stating "browser does not support spellcheck attribute" in Safari 3, Opera 9, Google Chrome, and Internet Explorer.</p>

<p><em>Note: Internet Explorer will reflect any attribute present in the page markup. If you include a <code>spellcheck</code> attribute on an element and then test whether that element's <abbr>DOM</abbr> node contains a <code>.spellcheck</code> property, IE will always return true. The safest way to check is to create a new element in script, like the example above, instead of testing a pre-existing element on your page.</em></p>

<h3>Conclusion</h3>

<p>You can start using the <code>spellcheck</code> attribute today, but it only affects the behavior of Firefox. However, it has no adverse effects in other browsers. Be sure to use either <code>spellcheck="true"</code> or <code>spellcheck="false"</code>, as these are the only values supported by Firefox (and the only valid values according to the HTML 5 spec as it stands today).</p>
<p></p><p>This item was originally posted at: <a href='http://blog.whatwg.org'>http://blog.whatwg.org</a> and is licensed under the <a href='http://www.opensource.org/licenses/mit-license.php'>MIT license</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.htmlfive.net/the-road-to-html-5-spellchecking/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Road to HTML 5: character encoding</title>
		<link>http://www.htmlfive.net/the-road-to-html-5-character-encoding/</link>
		<comments>http://www.htmlfive.net/the-road-to-html-5-character-encoding/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 16:15:13 +0000</pubDate>
		<dc:creator>Mark Pilgrim</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://blog.whatwg.org/?p=531</guid>
		<description><![CDATA[<p>Welcome back to my semi-regular column, "The Road to HTML 5," where I'll try to explain some of the <a href="http://wiki.whatwg.org/wiki/Differences_from_HTML4">new elements, attributes, and other features</a> in the upcoming HTML 5 specification.</p>

<p>The feature of the day is character encoding, specifically how to determine the character encoding of an HTML document.  I am never happier than when I am writing about character encoding.  But first, here is my standard "elevator pitch" description of what character encoding is:</p>

<blockquote cite="http://chardet.feedparser.org/docs/faq.html#faq.intro">
<p>When you think of "text," you probably think of "characters and symbols I see on my computer screen."  But computers don't deal in characters and symbols; they deal in bits and bytes.  Every piece of text you've ever seen on a computer screen is actually stored in a particular <em>character encoding</em>.  There are many different character encodings, some optimized for particular languages like Russian or Chinese or English, and others that can be used for multiple languages.  Very roughly speaking, the character encoding provides a mapping between the stuff you see on your screen and the stuff your computer actually stores in memory and on disk.</p> 
<p>In reality, it's more complicated than that.  Many characters are common to multiple encodings, but each encoding may use a different sequence of bytes to actually store those characters in memory or on disk.  So you can think of the character encoding as a kind of decryption key for the text.  Whenever someone gives you a sequence of bytes and claims it's "text," you need to know what character encoding they used so you can decode the bytes into characters and display them (or process them, or whatever).</p>
<p>&#8212; <a href="http://chardet.feedparser.org/docs/faq.html#faq.intro">source</a></p>
</blockquote>

<p>And once again, I'll repeat my standard set of background links for those of you who don't know anything about character encoding.  You <em>must</em> read Joel Spolsky's <a href="http://www.joelonsoftware.com/articles/Unicode.html">The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)</a>  You <em>should</em> read Tim Bray's three-part series, <a href="http://www.tbray.org/ongoing/When/200x/2003/04/06/Unicode">On the Goodness of Unicode</a>, <a href="http://www.tbray.org/ongoing/When/200x/2003/04/13/Strings">On Character Strings</a>, and <a href="http://www.tbray.org/ongoing/When/200x/2003/04/26/UTF">Characters vs. Bytes</a>, and <a href="http://www.w3.org/People/Dürst/papers.html">anything written by Martin D&#252;rst</a>.</p>

<p>I should also point out that <strong>you should always specify a character encoding on every HTML page you serve</strong>.  Not specifying an encoding <a href="http://code.google.com/p/doctype/wiki/ArticleUtf7">can lead to security vulnerabilities</a>.</p>

<p>So, how does your browser actually determine the character encoding of the stream of bytes that a web server sends?  If you're familiar with <acronym>HTTP</acronym> headers, you may have seen a header like this:</p>

<blockquote><p><code>Content-Type: text/html; charset="utf-8"</code></p></blockquote>

<p>Briefly, this says that the web server thinks it's sending you an HTML document, and that it thinks the document uses the <code>UTF-8</code> character encoding.  Unfortunately, in the whole magnificent soup of the world wide web, very few authors actually have control over their HTTP server.  Think <a href="http://www.blogger.com/">Blogger</a>: the content is provided by individuals, but the servers are run by Google.  So HTML 4 provided a way to specify the character encoding in the HTML document itself.  You've probably seen this too:</p>

<blockquote><p><code>&#60;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&#62;</code></p></blockquote>

<p>Briefly, this says that the web author thinks they have authored an HTML document using the <code>UTF-8</code> character encoding.  Now, you could easily imagine a situation where both the server <em>and</em> the document provide encoding information.  Furthermore, they might not match (especially if they're run by different people).  So which one wins?  Well, there's a precedence order in case the document is served with conflicting information.</p>

<p>This is what <a href="http://www.w3.org/TR/html401/charset.html#h-5.2.2">HTML 4.01 has to say</a> about the precedence order for determining the character encoding:</p>
<ol>
<li>User override (<i>e.g.</i> the user picked an encoding from a menu in their browser).</li>
<li>An HTTP "charset" parameter in a "Content-Type" field.</li>
<li>A META declaration with an "http-equiv" attribute set to "Content-Type" and a value set for "charset".</li>
<li>The charset attribute set on an element that designates an external resource.</li>
<li>Unspecified heuristic analysis.</li>
</ol>

<p>And <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#determining-the-character-encoding">this is what HTML 5 has to say about it</a>.  I won't quote the whole thing here, but suffice to say it's a 7-step algorithm; step 4 has 2 sub-steps, the first of which has 7 branches, one of which has 8 sub-steps, one of which actually links to a separate algorithm that itself has 7 steps...  It goes on like that for a while.  The gist of it is</p>

<ol>
<li>User override.</li>
<li>An HTTP "charset" parameter in a "Content-Type" field.</li>
<li>A Byte Order Mark before any other data in the HTML document itself.</li>
<li>A META declaration with a "charset" attribute.</li>
<li>A META declaration with an "http-equiv" attribute set to "Content-Type" and a value set for "charset".</li>
<li>Unspecified heuristic analysis.</li>
</ol>

<p>...and then...</p>

<ol>
<li>Normalize the given character encoding string according to the Charset Alias Matching rules defined in Unicode Technical Standard #22.</li>
<li>Override some problematic encodings, <i>i.e.</i> intentionally treat some encodings as if they were different encodings.  The most common override is treating <code>US-ASCII</code> and <code>ISO-8859-1</code> as <code>Windows-1252</code>, but there are <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#character-encoding-requirements">several other encoding overrides listed in this table</a>.  As the specification notes, "The requirement to treat certain encodings as other encodings according to the table above is a willful violation of the W3C Character Model specification."</li>
</ol>

<p>Two things should leap out at you here.  First, <acronym title="what the frack">WTF</acronym> is a <a href="http://code.google.com/p/doctype/wiki/MetaCharsetAttribute"><code>&#60;meta charset&#62;</code> attribute</a>?  Well, it's exactly what it sounds like.  It looks like this:</p>

<blockquote><p><code>&#60;meta charset=UTF-8&#62;</code></p></blockquote>

<p>I was able to find only scattered discussion about this attribute on the WHATWG mailing list.</p>

<ul>
<li>March 2006: <a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2006-March/thread.html#5959">Internet character encoding declaration</a>, specifically <a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2006-March/006004.html">this post by Lachlan Hunt</a> which laid out the requirements for "paving the cowpaths" of common authoring mistakes.</li>
<li>June 2007: <a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2007-June/thread.html#11949">Internal character encoding declaration, Drop UTF-32, and UTF and BOM terminology</a></li>
</ul>

<p>The best explanation of the new <code>&#60;meta charset&#62;</code> attribute was given a few months later, in an unrelated thread, on a separate mailing list.  <a href="http://lists.w3.org/Archives/Public/public-html/2007Jul/0550.html">Andrew Sidwell explains</a>:</p>

<blockquote cite="http://lists.w3.org/Archives/Public/public-html/2007Jul/0550.html">
<p>The rationale for the <code>&#60;meta charset=""&#62;</code> attribute combination is that UAs already implement it, because people tend to leave things unquoted, like:</p>
<p><code>&#60;META HTTP-EQUIV=Content-Type CONTENT=text/html; charset=ISO-8859-1&#62;</code></p>
</blockquote>

<p>(There are even a few <a href="http://simon.html5.org/test/html/parsing/encoding/"><code>&#60;meta charset&#62;</code> test cases</a> if you don't believe that browsers already do this.)</p>

<p>Second, who the f&#8212; does the WHATWG think they are specifying "a willful violation of the W3C Character Model specification"&#x203D;  This is a fair question.  As with many such questions, the answer is that HTML 5 is only codifying what browsers do already.  ISO-8859-1 and Windows-1252 are very similar encodings.  One place they differ is in so-called "smart quotes" and "curly apostrophes" &#8212; the pretty little typographical flourishes that authors love and that Microsoft Word (and many other editors) output by default.  Many authors specify a ISO-8559-1 or US-ASCII encoding (because they copied that part of their template from somewhere else), but then they use curly quotes from the Windows-1252 encoding.  This mistake is so widespread that browsers already treat ISO-8859-1 as Windows-1252.  HTML 5 is just "paving the cowpaths" here.</p>

<p>To sum up: character encoding is complicated, and it has not been made any easier by several decades of poorly written software used by copy-and-paste&#8211;educated authors.  You should <strong>always</strong> specify a character encoding on <strong>every</strong> HTML document, or <a href="http://code.google.com/p/doctype/wiki/ArticleUtf7">bad things will happen</a>.  You can do it the hard way (HTTP <code>Content-Type</code> header), the easy way (<code>&#60;meta http-equiv&#62;</code> declaration), or the new way (<a href="http://code.google.com/p/doctype/wiki/MetaCharsetAttribute"><code>&#60;meta charset&#62;</code> attribute</a>), but please do it.  The web thanks you.</p>
]]></description>
			<content:encoded><![CDATA[<p>Welcome back to my semi-regular column, "The Road to HTML 5," where I'll try to explain some of the <a href="http://wiki.whatwg.org/wiki/Differences_from_HTML4">new elements, attributes, and other features</a> in the upcoming HTML 5 specification.</p>

<p>The feature of the day is character encoding, specifically how to determine the character encoding of an HTML document.  I am never happier than when I am writing about character encoding.  But first, here is my standard "elevator pitch" description of what character encoding is:</p>

<blockquote cite="http://chardet.feedparser.org/docs/faq.html#faq.intro">
<p>When you think of "text," you probably think of "characters and symbols I see on my computer screen."  But computers don't deal in characters and symbols; they deal in bits and bytes.  Every piece of text you've ever seen on a computer screen is actually stored in a particular <em>character encoding</em>.  There are many different character encodings, some optimized for particular languages like Russian or Chinese or English, and others that can be used for multiple languages.  Very roughly speaking, the character encoding provides a mapping between the stuff you see on your screen and the stuff your computer actually stores in memory and on disk.</p> 
<p>In reality, it's more complicated than that.  Many characters are common to multiple encodings, but each encoding may use a different sequence of bytes to actually store those characters in memory or on disk.  So you can think of the character encoding as a kind of decryption key for the text.  Whenever someone gives you a sequence of bytes and claims it's "text," you need to know what character encoding they used so you can decode the bytes into characters and display them (or process them, or whatever).</p>
<p>&mdash; <a href="http://chardet.feedparser.org/docs/faq.html#faq.intro">source</a></p>
</blockquote>

<p>And once again, I'll repeat my standard set of background links for those of you who don't know anything about character encoding.  You <em>must</em> read Joel Spolsky's <a href="http://www.joelonsoftware.com/articles/Unicode.html">The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)</a>  You <em>should</em> read Tim Bray's three-part series, <a href="http://www.tbray.org/ongoing/When/200x/2003/04/06/Unicode">On the Goodness of Unicode</a>, <a href="http://www.tbray.org/ongoing/When/200x/2003/04/13/Strings">On Character Strings</a>, and <a href="http://www.tbray.org/ongoing/When/200x/2003/04/26/UTF">Characters vs. Bytes</a>, and <a href="http://www.w3.org/People/Dürst/papers.html">anything written by Martin D&uuml;rst</a>.</p>

<p>I should also point out that <strong>you should always specify a character encoding on every HTML page you serve</strong>.  Not specifying an encoding <a href="http://code.google.com/p/doctype/wiki/ArticleUtf7">can lead to security vulnerabilities</a>.</p>

<p>So, how does your browser actually determine the character encoding of the stream of bytes that a web server sends?  If you're familiar with <acronym>HTTP</acronym> headers, you may have seen a header like this:</p>

<blockquote><p><code>Content-Type: text/html; charset="utf-8"</code></p></blockquote>

<p>Briefly, this says that the web server thinks it's sending you an HTML document, and that it thinks the document uses the <code>UTF-8</code> character encoding.  Unfortunately, in the whole magnificent soup of the world wide web, very few authors actually have control over their HTTP server.  Think <a href="http://www.blogger.com/">Blogger</a>: the content is provided by individuals, but the servers are run by Google.  So HTML 4 provided a way to specify the character encoding in the HTML document itself.  You've probably seen this too:</p>

<blockquote><p><code>&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;</code></p></blockquote>

<p>Briefly, this says that the web author thinks they have authored an HTML document using the <code>UTF-8</code> character encoding.  Now, you could easily imagine a situation where both the server <em>and</em> the document provide encoding information.  Furthermore, they might not match (especially if they're run by different people).  So which one wins?  Well, there's a precedence order in case the document is served with conflicting information.</p>

<p>This is what <a href="http://www.w3.org/TR/html401/charset.html#h-5.2.2">HTML 4.01 has to say</a> about the precedence order for determining the character encoding:</p>
<ol>
<li>User override (<i>e.g.</i> the user picked an encoding from a menu in their browser).</li>
<li>An HTTP "charset" parameter in a "Content-Type" field.</li>
<li>A META declaration with an "http-equiv" attribute set to "Content-Type" and a value set for "charset".</li>
<li>The charset attribute set on an element that designates an external resource.</li>
<li>Unspecified heuristic analysis.</li>
</ol>

<p>And <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#determining-the-character-encoding">this is what HTML 5 has to say about it</a>.  I won't quote the whole thing here, but suffice to say it's a 7-step algorithm; step 4 has 2 sub-steps, the first of which has 7 branches, one of which has 8 sub-steps, one of which actually links to a separate algorithm that itself has 7 steps...  It goes on like that for a while.  The gist of it is</p>

<ol>
<li>User override.</li>
<li>An HTTP "charset" parameter in a "Content-Type" field.</li>
<li>A Byte Order Mark before any other data in the HTML document itself.</li>
<li>A META declaration with a "charset" attribute.</li>
<li>A META declaration with an "http-equiv" attribute set to "Content-Type" and a value set for "charset".</li>
<li>Unspecified heuristic analysis.</li>
</ol>

<p>...and then...</p>

<ol>
<li>Normalize the given character encoding string according to the Charset Alias Matching rules defined in Unicode Technical Standard #22.</li>
<li>Override some problematic encodings, <i>i.e.</i> intentionally treat some encodings as if they were different encodings.  The most common override is treating <code>US-ASCII</code> and <code>ISO-8859-1</code> as <code>Windows-1252</code>, but there are <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#character-encoding-requirements">several other encoding overrides listed in this table</a>.  As the specification notes, "The requirement to treat certain encodings as other encodings according to the table above is a willful violation of the W3C Character Model specification."</li>
</ol>

<p>Two things should leap out at you here.  First, <acronym title="what the frack">WTF</acronym> is a <a href="http://code.google.com/p/doctype/wiki/MetaCharsetAttribute"><code>&lt;meta charset&gt;</code> attribute</a>?  Well, it's exactly what it sounds like.  It looks like this:</p>

<blockquote><p><code>&lt;meta charset=UTF-8&gt;</code></p></blockquote>

<p>I was able to find only scattered discussion about this attribute on the WHATWG mailing list.</p>

<ul>
<li>March 2006: <a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2006-March/thread.html#5959">Internet character encoding declaration</a>, specifically <a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2006-March/006004.html">this post by Lachlan Hunt</a> which laid out the requirements for "paving the cowpaths" of common authoring mistakes.</li>
<li>June 2007: <a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2007-June/thread.html#11949">Internal character encoding declaration, Drop UTF-32, and UTF and BOM terminology</a></li>
</ul>

<p>The best explanation of the new <code>&lt;meta charset&gt;</code> attribute was given a few months later, in an unrelated thread, on a separate mailing list.  <a href="http://lists.w3.org/Archives/Public/public-html/2007Jul/0550.html">Andrew Sidwell explains</a>:</p>

<blockquote cite="http://lists.w3.org/Archives/Public/public-html/2007Jul/0550.html">
<p>The rationale for the <code>&lt;meta charset=""&gt;</code> attribute combination is that UAs already implement it, because people tend to leave things unquoted, like:</p>
<p><code>&lt;META HTTP-EQUIV=Content-Type CONTENT=text/html; charset=ISO-8859-1&gt;</code></p>
</blockquote>

<p>(There are even a few <a href="http://simon.html5.org/test/html/parsing/encoding/"><code>&lt;meta charset&gt;</code> test cases</a> if you don't believe that browsers already do this.)</p>

<p>Second, who the f&mdash; does the WHATWG think they are specifying "a willful violation of the W3C Character Model specification"&#x203D;  This is a fair question.  As with many such questions, the answer is that HTML 5 is only codifying what browsers do already.  ISO-8859-1 and Windows-1252 are very similar encodings.  One place they differ is in so-called "smart quotes" and "curly apostrophes" &mdash; the pretty little typographical flourishes that authors love and that Microsoft Word (and many other editors) output by default.  Many authors specify a ISO-8559-1 or US-ASCII encoding (because they copied that part of their template from somewhere else), but then they use curly quotes from the Windows-1252 encoding.  This mistake is so widespread that browsers already treat ISO-8859-1 as Windows-1252.  HTML 5 is just "paving the cowpaths" here.</p>

<p>To sum up: character encoding is complicated, and it has not been made any easier by several decades of poorly written software used by copy-and-paste&ndash;educated authors.  You should <strong>always</strong> specify a character encoding on <strong>every</strong> HTML document, or <a href="http://code.google.com/p/doctype/wiki/ArticleUtf7">bad things will happen</a>.  You can do it the hard way (HTTP <code>Content-Type</code> header), the easy way (<code>&lt;meta http-equiv&gt;</code> declaration), or the new way (<a href="http://code.google.com/p/doctype/wiki/MetaCharsetAttribute"><code>&lt;meta charset&gt;</code> attribute</a>), but please do it.  The web thanks you.</p>
<p></p><p>This item was originally posted at: <a href='http://blog.whatwg.org'>http://blog.whatwg.org</a> and is licensed under the <a href='http://www.opensource.org/licenses/mit-license.php'>MIT license</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.htmlfive.net/the-road-to-html-5-character-encoding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Road to HTML 5: getElementsByClassName()</title>
		<link>http://www.htmlfive.net/the-road-to-html-5-getelementsbyclassname/</link>
		<comments>http://www.htmlfive.net/the-road-to-html-5-getelementsbyclassname/#comments</comments>
		<pubDate>Tue, 11 Nov 2008 19:01:05 +0000</pubDate>
		<dc:creator>Mark Pilgrim</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[WHATWG]]></category>

		<guid isPermaLink="false">http://blog.whatwg.org/?p=356</guid>
		<description><![CDATA[<p>Welcome back to my semi-regular column, "The Road to HTML 5," where I'll try to explain some of the <a href="http://wiki.whatwg.org/wiki/Differences_from_HTML4">new elements, attributes, and other features</a> in the upcoming HTML 5 specification.</p>

<p>The feature of the day is <a href="http://code.google.com/p/doctype/wiki/DocumentGetElementsByClassNameMethod"><code>getElementsByClassName()</code></a>.  Long desired by web developers and implemented in Javascript libraries like <a href="http://www.prototypejs.org/api/element/getElementsByClassName">Prototype</a>, this function does exactly what it says on the tin: it returns a list of elements in the DOM that define one or more classnames in the <code>class</code> attribute.  <code>getElementsByClassName()</code> exists as a method of the <code>document</code> object (for searching the entire DOM), as well as on each <code>HTMLElement</code> object (for searching the children of an element).</p>

<p><a href="http://www.whatwg.org/specs/web-apps/current-work/#dom-document-getelementsbyclassname">The HTML 5 specification defines <code>getElementsByClassName()</code>:</a></p>

<blockquote cite="http://www.whatwg.org/specs/web-apps/current-work/#dom-document-getelementsbyclassname">
<p>The <code>getElementsByClassName(<var>classNames</var>)</code> method takes a string that contains an <a href="http://www.whatwg.org/specs/web-apps/current-work/#unordered-set-of-unique-space-separated-tokens">unordered set of unique space-separated tokens</a> representing classes. When called, the method must return a live <code>NodeList</code> object containing all the elements in the document, in <a href="http://www.whatwg.org/specs/web-apps/current-work/#tree-order">tree order</a>, that have all the classes specified in that argument, having obtained the classes by <a href="http://www.whatwg.org/specs/web-apps/current-work/#split-a-string-on-spaces">splitting a string on spaces</a>. If there are no tokens specified in the argument, then the method must return an empty <code>NodeList</code>. If the document is in <a href="http://www.whatwg.org/specs/web-apps/current-work/#quirks-mode">quirks mode</a>, then the comparisons for the classes must be done in an <a href="http://www.whatwg.org/specs/web-apps/current-work/#ascii-case-insensitive">ASCII case-insensitive</a> manner, otherwise, the comparisons must be done in a <a href="http://www.whatwg.org/specs/web-apps/current-work/#case-sensitive">case-sensitive</a> manner.</p>
</blockquote>

<h3>A Brief History of getElementsByClassName()</h3>

<ul>
<li>September 2005: <a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2005-September/004685.html">getElementsByClassName() Implementation Questions</a> and followups discuss whether <code>getElementsByClassName()</code> should take a string with multiple classnames, and if so, what that would mean.  <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2005-September/004716.html">Despite early protests</a>, it was eventually decided that <code>getElementsByClassName()</code> <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2005-November/005064.html">should take multiple classnames in a single string, separated by spaces</a>, and that the function should return elements that define <em>all</em> of given classnames.</li>
<li>February 2006: "<a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-February/005703.html">I see this is still an open issue</a>."</li>
<li>October 2006: "<a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-October/007407.html">This omnibus edition of your WHATWG mail includes replies to 50 or so separate e-mails about getElementsByClassName()</a>."</li>
<li>February 2007: "<a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2007-October/012651.html">I landed support for this on the Mozilla trunk, and it will appear in upcoming Firefox alphas and betas. The array argument turned out to be quite a pain to implement, so we cut it</a>."  Ian Hickson responds: "I've changed the spec to use a space-separated list. ... I've dropped the array form altogether."</li>
<li>March 2007: John Resig puts Firefox 3's implementation to the test in <a href="http://ejohn.org/blog/getelementsbyclassname-speed-comparison/">getElementsByClassName Speed Comparison</a>.</li>
<li>July 2007: "<a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2007-July/012167.html">I suggest that participants in this thread reacquaint themselves with the discussion in the previous one before having it again</a>."  Good luck with that.</li>
<li>September 2007: "<a href="http://dev.opera.com/articles/view/new-development-techniques-using-opera-k/">A popular and useful feature [in Opera 9.5] will be the addition of native support for getElementByClassName from HTML5</a>."</li>
<li>December 2007: "<a href="http://webkit.org/blog/153/webkit-gets-native-getelementsbyclassname/">Last week WebKit joined upcoming versions of Firefox and Opera in supporting [getElementsByClassName]</a>."</li>
<li>December 2007: "<a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2007-December/013119.html">Currently getElementsByClassName is specified as always being case sensitive. This would be fine, except that the primary other use of html class names (CSS selector matching) is only case sensitive in standards mode. This leads to situations ... in which CSS and getElementsByClassName match different results</a>."</li>
<li>July 2008: Ian Hickson responds: "<a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2008-July/015391.html">I've made it consistent with how classes work in CSS (case-insensitive for quirks and case-sensitive otherwise)</a>."</li>
</ul>

<h3>Can We Use It?</h3>

<p>Yes We Can!  As you can tell from the timeline, <code>getElementsByClassName()</code> is supported natively in Firefox 3, Opera 9.5, Safari 3.1, and all versions of Google Chrome.  It is not available in any version of Microsoft Internet Explorer.  (IE 8 beta 2 is the latest version as of this writing.)  To use it in browsers that do not support it natively, you will need a wrapper script.  There are many such scripts; I myself am partial to <a href="http://www.robertnyman.com/2008/05/27/the-ultimate-getelementsbyclassname-anno-2008/">Robert Nyman's Ultimate GetElementsByClassName</a>.  It uses the native <code>getElementsByClassName()</code> method in modern browsers that support it, then falls back to the little-known <a href="http://www.w3.org/TR/2004/NOTE-DOM-Level-3-XPath-20040226/xpath.html#XPathEvaluator-evaluate"><code>document.evaluate()</code> method</a>, which is supported by older versions of Firefox (since at least 1.5) and Opera (since at least 9.27).  If all else fails, Robert's script falls back to recursively traversing the DOM and collecting elements that match the given classnames.</p>

<h3>And in conclusion</h3>

<p><code>getElementsByClassName()</code> is well-supported across all modern browsers except IE, and a performance-optimized open source wrapper script can cover IE and older browsers.</p>
]]></description>
			<content:encoded><![CDATA[<p>Welcome back to my semi-regular column, "The Road to HTML 5," where I'll try to explain some of the <a href="http://wiki.whatwg.org/wiki/Differences_from_HTML4">new elements, attributes, and other features</a> in the upcoming HTML 5 specification.</p>

<p>The feature of the day is <a href="http://code.google.com/p/doctype/wiki/DocumentGetElementsByClassNameMethod"><code>getElementsByClassName()</code></a>.  Long desired by web developers and implemented in Javascript libraries like <a href="http://www.prototypejs.org/api/element/getElementsByClassName">Prototype</a>, this function does exactly what it says on the tin: it returns a list of elements in the DOM that define one or more classnames in the <code>class</code> attribute.  <code>getElementsByClassName()</code> exists as a method of the <code>document</code> object (for searching the entire DOM), as well as on each <code>HTMLElement</code> object (for searching the children of an element).</p>

<p><a href="http://www.whatwg.org/specs/web-apps/current-work/#dom-document-getelementsbyclassname">The HTML 5 specification defines <code>getElementsByClassName()</code>:</a></p>

<blockquote cite="http://www.whatwg.org/specs/web-apps/current-work/#dom-document-getelementsbyclassname">
<p>The <code>getElementsByClassName(<var>classNames</var>)</code> method takes a string that contains an <a href="http://www.whatwg.org/specs/web-apps/current-work/#unordered-set-of-unique-space-separated-tokens">unordered set of unique space-separated tokens</a> representing classes. When called, the method must return a live <code>NodeList</code> object containing all the elements in the document, in <a href="http://www.whatwg.org/specs/web-apps/current-work/#tree-order">tree order</a>, that have all the classes specified in that argument, having obtained the classes by <a href="http://www.whatwg.org/specs/web-apps/current-work/#split-a-string-on-spaces">splitting a string on spaces</a>. If there are no tokens specified in the argument, then the method must return an empty <code>NodeList</code>. If the document is in <a href="http://www.whatwg.org/specs/web-apps/current-work/#quirks-mode">quirks mode</a>, then the comparisons for the classes must be done in an <a href="http://www.whatwg.org/specs/web-apps/current-work/#ascii-case-insensitive">ASCII case-insensitive</a> manner, otherwise, the comparisons must be done in a <a href="http://www.whatwg.org/specs/web-apps/current-work/#case-sensitive">case-sensitive</a> manner.</p>
</blockquote>

<h3>A Brief History of getElementsByClassName()</h3>

<ul>
<li>September 2005: <a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2005-September/004685.html">getElementsByClassName() Implementation Questions</a> and followups discuss whether <code>getElementsByClassName()</code> should take a string with multiple classnames, and if so, what that would mean.  <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2005-September/004716.html">Despite early protests</a>, it was eventually decided that <code>getElementsByClassName()</code> <a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2005-November/005064.html">should take multiple classnames in a single string, separated by spaces</a>, and that the function should return elements that define <em>all</em> of given classnames.</li>
<li>February 2006: "<a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-February/005703.html">I see this is still an open issue</a>."</li>
<li>October 2006: "<a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2006-October/007407.html">This omnibus edition of your WHATWG mail includes replies to 50 or so separate e-mails about getElementsByClassName()</a>."</li>
<li>February 2007: "<a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2007-October/012651.html">I landed support for this on the Mozilla trunk, and it will appear in upcoming Firefox alphas and betas. The array argument turned out to be quite a pain to implement, so we cut it</a>."  Ian Hickson responds: "I've changed the spec to use a space-separated list. ... I've dropped the array form altogether."</li>
<li>March 2007: John Resig puts Firefox 3's implementation to the test in <a href="http://ejohn.org/blog/getelementsbyclassname-speed-comparison/">getElementsByClassName Speed Comparison</a>.</li>
<li>July 2007: "<a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2007-July/012167.html">I suggest that participants in this thread reacquaint themselves with the discussion in the previous one before having it again</a>."  Good luck with that.</li>
<li>September 2007: "<a href="http://dev.opera.com/articles/view/new-development-techniques-using-opera-k/">A popular and useful feature [in Opera 9.5] will be the addition of native support for getElementByClassName from HTML5</a>."</li>
<li>December 2007: "<a href="http://webkit.org/blog/153/webkit-gets-native-getelementsbyclassname/">Last week WebKit joined upcoming versions of Firefox and Opera in supporting [getElementsByClassName]</a>."</li>
<li>December 2007: "<a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2007-December/013119.html">Currently getElementsByClassName is specified as always being case sensitive. This would be fine, except that the primary other use of html class names (CSS selector matching) is only case sensitive in standards mode. This leads to situations ... in which CSS and getElementsByClassName match different results</a>."</li>
<li>July 2008: Ian Hickson responds: "<a href="http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2008-July/015391.html">I've made it consistent with how classes work in CSS (case-insensitive for quirks and case-sensitive otherwise)</a>."</li>
</ul>

<h3>Can We Use It?</h3>

<p>Yes We Can!  As you can tell from the timeline, <code>getElementsByClassName()</code> is supported natively in Firefox 3, Opera 9.5, Safari 3.1, and all versions of Google Chrome.  It is not available in any version of Microsoft Internet Explorer.  (IE 8 beta 2 is the latest version as of this writing.)  To use it in browsers that do not support it natively, you will need a wrapper script.  There are many such scripts; I myself am partial to <a href="http://www.robertnyman.com/2008/05/27/the-ultimate-getelementsbyclassname-anno-2008/">Robert Nyman's Ultimate GetElementsByClassName</a>.  It uses the native <code>getElementsByClassName()</code> method in modern browsers that support it, then falls back to the little-known <a href="http://www.w3.org/TR/2004/NOTE-DOM-Level-3-XPath-20040226/xpath.html#XPathEvaluator-evaluate"><code>document.evaluate()</code> method</a>, which is supported by older versions of Firefox (since at least 1.5) and Opera (since at least 9.27).  If all else fails, Robert's script falls back to recursively traversing the DOM and collecting elements that match the given classnames.</p>

<h3>And in conclusion</h3>

<p><code>getElementsByClassName()</code> is well-supported across all modern browsers except IE, and a performance-optimized open source wrapper script can cover IE and older browsers.</p>
<p></p><p>This item was originally posted at: <a href='http://blog.whatwg.org'>http://blog.whatwg.org</a> and is licensed under the <a href='http://www.opensource.org/licenses/mit-license.php'>MIT license</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.htmlfive.net/the-road-to-html-5-getelementsbyclassname/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Road to HTML 5 &#8211; Episode 1: the section element</title>
		<link>http://www.htmlfive.net/the-road-to-html-5-episode-1-the-section-element/</link>
		<comments>http://www.htmlfive.net/the-road-to-html-5-episode-1-the-section-element/#comments</comments>
		<pubDate>Wed, 05 Nov 2008 23:00:20 +0000</pubDate>
		<dc:creator>Mark Pilgrim</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Weekly Review]]></category>

		<guid isPermaLink="false">http://blog.whatwg.org/?p=344</guid>
		<description><![CDATA[<p>Welcome to a new semi-regular column, "The Road to HTML 5," where I'll try to explain some of the <a href="http://wiki.whatwg.org/wiki/Differences_from_HTML4">new elements, attributes, and other features</a> in the upcoming HTML 5 specification.</p>

<p>The element of the day is <a href="http://code.google.com/p/doctype/wiki/SectionElement">the <code>&#60;section&#62;</code> element</a>.</p>

<blockquote cite="http://www.whatwg.org/specs/web-apps/current-work/#the-section-element">
<p>The <code>section</code> element represents a generic document or application section. A section, in this context, is a thematic grouping of content, typically with a header, possibly with a footer.  Examples of sections would be chapters, the various tabbed pages in a tabbed dialog box, or the numbered sections of a thesis. A Web site's home page could be split into sections for an introduction, news items, contact information.</p>
</blockquote>

<p>Discussion of sections and headers dates back several years. <a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2004-November/002362.html">In November 2004, Ian Hickson wrote</a>:</p>

<blockquote>
<p>Basically I want three things:</p>

<ol>
<li>It has to be possible to take existing markup (which correctly uses &#60;code &#62;</code>&#60;h1&#62;</code>-&#60;code &#62;</code>&#60;h6&#62;</code>) and wrap the sections up with &#60;code &#62;</code>&#60;section&#62;</code> (and the other new section elements) and have it be correct markup. Basically, allowing authors to replace &#60;code &#62;</code>&#60;div class="section"&#62;</code> with &#60;code &#62;</code>&#60;section&#62;</code>, &#60;code &#62;</code>&#60;div class="post"&#62;</code> with &#60;code &#62;</code>&#60;article&#62;</code>, etc.</li>
<li>It has to be possible to write new documents that use the section elements and have the headers be automatically styled to the right depth (and maybe automatically numbered, with appropriate CSS), and yet still be readable in legacy UAs, without having to think about old UAs. Basically, the header element has to be header-like in old browsers.</li>
<li>It shouldn't be too easy to end up with meaningless markup when doing either of the above. So a random &#60;code &#62;</code>&#60;h4&#62;</code> in the middle of an &#60;code &#62;</code>&#60;h2&#62;</code> and an &#60;code &#62;</code>&#60;h3&#62;</code> has to be defined as meaning _something_.</li>
</ol>
<p>At the moment what I'm thinking of doing is this (most of these ideas are in the draft at the moment, but mostly in contradictory ways):</p>
<p>The section elements would be:</p>
<blockquote>
<p>&#60;code &#62;</code>&#60;body&#62;</code> &#60;code &#62;</code>&#60;section&#62;</code> &#60;code &#62;</code>&#60;article&#62;</code> &#60;code &#62;</code>&#60;navigation&#62;</code> &#60;code &#62;</code>&#60;sidebar&#62;</code></p>
</blockquote>
<p>The header elements would be:</p>
<blockquote>
<p>&#60;code &#62;</code>&#60;header&#62;</code> &#60;code &#62;</code>&#60;h1&#62;</code> &#60;code &#62;</code>&#60;h2&#62;</code> &#60;code &#62;</code>&#60;h3&#62;</code> &#60;code &#62;</code>&#60;h4&#62;</code> &#60;code &#62;</code>&#60;h5&#62;</code> &#60;code &#62;</code>&#60;h6&#62;</code></p>
</blockquote>
<p>&#60;code &#62;</code>&#60;h1&#62;</code> gives the heading of the current section.</p>
<p>&#60;code &#62;</code>&#60;header&#62;</code> wraps block-level content to mark the whole thing as a header, so that you can have, e.g., subtitles, or "Welcome to" paragraphs before a header, or "Presented by" kind of information. &#60;code &#62;</code>&#60;header&#62;</code> is equivalent to an &#60;code &#62;</code>&#60;h1&#62;</code>. The first highest-level header in the &#60;code &#62;</code>&#60;header&#62;</code> is the "title" of the section for outlining purposes.</p>
<p>&#60;code &#62;</code>&#60;h2&#62;</code> to &#60;code &#62;</code>&#60;h6&#62;</code> are subsection headings when used in &#60;code &#62;</code>&#60;body&#62;</code>, and equivalent to &#60;code &#62;</code>&#60;h1&#62;</code> when used in one of the section elements.</p>
<p>&#60;code &#62;</code>&#60;h1&#62;</code> automatically sizes to fit the current nesting depth. This could be a problem in CSS since CSS can't handle this kind of thing well -- it has no "or" operator at the simple selector level.</p>
<p>&#60;code &#62;</code>&#60;h2&#62;</code>-&#60;code &#62;</code>&#60;h6&#62;</code> keep their legacy renderings for compatibility.</p>
</blockquote>

<p>Further discussion:</p>

<ul>
<li>August 2004: <a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2004-August/thread.html#1989">&#60;section&#62; and headings</a></li>
<li>September 2004: <a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2004-September/thread.html#2188">&#60;section&#62; and headings</a></li>
<li>November 2004: <a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2004-November/thread.html#2443">The Section Header Problem</a></li>
<li>March 2005: <a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2005-March/thread.html#3333">&#60;h1&#62; to &#60;h6&#62; in &#60;body&#62;</a></li>
<li>April 2005: <a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2005-April/thread.html#3377">&#60;section&#62;and headings and other threads</a>
</li></ul>

<p>Fast-forward to modern times.  Using the <code>&#60;section&#62;</code> element instead of, say, <code>&#60;div class="section"&#62;</code>, seems like a no-brainer.  Unfortunately, there's a catch.  (Hey, it's the web; there's always a catch.)  Not all modern browsers recognize the <code>&#60;section&#62;</code> element, which means that they fall back to their default handling of unknown elements.</p>

<h3>A long digression into browsers' handling of unknown elements</h3>

<p>Every browser has a master list of HTML elements that it supports.  For example, Mozilla Firefox's list is stored in <a href="http://mxr.mozilla.org/seamonkey/source/parser/htmlparser/src/nsElementTable.cpp">nsElementTable.cpp</a>.  Elements not in this list are treated as "unknown elements."  There are two fundamental problems with unknown elements:</p>

<ol>
<li><b>How should the element be styled?</b>  By default, <code>&#60;p&#62;</code> has spacing on the top and bottom, <code>&#60;blockquote&#62;</code> is indented with a left margin, and <code>&#60;h1&#62;</code> is displayed in a larger font.</li>
<li><b>What should the element's DOM look like?</b>  Mozilla's <code>nsElementTable.cpp</code> includes information about what kinds of other elements each element can contain.  If you include markup like <code>&#60;p&#62;&#60;p&#62;</code>, the second paragraph element implicitly closes the first one, so the elements end up as siblings, not parent-and-child.  But if you write <code>&#60;p&#62;&#60;span&#62;</code>, the <code>span</code> does not close the paragraph, because Firefox knows that <code>&#60;p&#62;</code> is a block element that can contain the inline element <code>&#60;span&#62;</code>.  So the <code>&#60;span&#62;</code> ends up as a child of the <code>&#60;p&#62;</code> in the DOM.</li>
</ol>

<p>Different browsers answer these questions in different ways.  (Shocking, I know.)  Of the major browsers, Microsoft Internet Explorer's answer to both questions is the most problematic.</p>

<p>The first question should be relatively simple to answer: don't give any special styling to unknown elements.  Just let them inherit whatever CSS properties are in effect wherever they appear on the page, and let the page author specify all styling with CSS.  Unfortunately, Internet Explorer does not allow styling on unknown elements.  For example, if you had this markup:</p>

<blockquote><pre><code>&#60;style type="text/css"&#62;
  section { border: 1px solid red }
&#60;/style&#62;
...
&#60;section&#62;
&#60;h1&#62;Welcome to Initech&#60;/h1&#62;
&#60;p&#62;This is our &#60;span&#62;home page&#60;/span&#62;.&#60;/p&#62;
&#60;/section&#62;</code></pre></blockquote>

<p>Internet Explorer (up to and including IE8 beta 2) will not put a red border around the section.</p>

<p>The second problem is the DOM that browsers create when they encounter unknown elements.  Again, the most problematic browser is Internet Explorer.  If IE doesn't explicitly recognize the element name, it will insert the element into the DOM <em>as an empty node with no children</em>.  All the elements that you would expect to be direct children of the unknown element will actually be inserted as siblings instead.  I've posted <a href="http://code.google.com/p/doctype/wiki/SectionElement">an ASCII graph that illustrates this mismatch</a>.</p>

<p>Sjoerd Visscher discovered a workaround for this problem: after you <a href="http://xopus.com/devblog/2008/style-unknown-elements.html">create a dummy element with that name</a>, IE will recognize the element enough to let you style it with CSS.  You can put the script in the <code>&#60;head&#62;</code> of your page, and there is no need to ever insert it into the DOM.  Simply creating the element once (per page) is enough to teach IE to style the element it doesn't recognize.  Sample code and markup:</p>

<blockquote><pre><code>&#60;html&#62;
&#60;head&#62;
&#60;style type="text/css"&#62;
  section { display: block; border: 1px solid red }
&#60;/style&#62;
<b>&#60;script type="text/javascript"&#62;
  document.createElement("section");
&#60;/script&#62;</b>
&#60;/head&#62;
&#60;body&#62;
&#60;section&#62;
&#60;h1&#62;Welcome to Initech&#60;/h1&#62;
&#60;p&#62;This is our &#60;span&#62;home page&#60;/span&#62;.&#60;/p&#62;
&#60;/section&#62;
&#60;/body&#62;
&#60;/html&#62;</code></pre></blockquote>

<p>This hack works in IE 6, IE 7, and IE 8 beta 1, but it doesn't work in IE 8 beta 2.  (<a href="http://connect.microsoft.com/IE/feedback/ViewFeedback.aspx?FeedbackID=364356">bug report</a>, <a href="http://philip.html5.org/tests/ie8/cases/unknown-element-styling.html">test case</a>)  The purpose of this illustration is not to blame IE; there's no specification that says what the DOM ought to look like in this case, so IE's handling of the "unknown element" problem is not any more or less correct than any other browser.  With the <code>createElement</code> workaround, you can use the <code>&#60;section&#62;</code> element (or any other new HTML 5 element) in all browsers except IE 8 beta 2.  I am not aware of any workaround for this problem.</p>

<h3>And in conclusion</h3>

<p>The <code>&#60;section&#62;</code> element is a very straightforward HTML 5 feature that you can't actually use yet.</p>
]]></description>
			<content:encoded><![CDATA[<p>Welcome to a new semi-regular column, "The Road to HTML 5," where I'll try to explain some of the <a href="http://wiki.whatwg.org/wiki/Differences_from_HTML4">new elements, attributes, and other features</a> in the upcoming HTML 5 specification.</p>

<p>The element of the day is <a href="http://code.google.com/p/doctype/wiki/SectionElement">the <code>&lt;section&gt;</code> element</a>.</p>

<blockquote cite="http://www.whatwg.org/specs/web-apps/current-work/#the-section-element">
<p>The <code>section</code> element represents a generic document or application section. A section, in this context, is a thematic grouping of content, typically with a header, possibly with a footer.  Examples of sections would be chapters, the various tabbed pages in a tabbed dialog box, or the numbered sections of a thesis. A Web site's home page could be split into sections for an introduction, news items, contact information.</p>
</blockquote>

<p>Discussion of sections and headers dates back several years. <a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2004-November/002362.html">In November 2004, Ian Hickson wrote</a>:</p>

<blockquote>
<p>Basically I want three things:</p>

<ol>
<li>It has to be possible to take existing markup (which correctly uses &lt;code &gt;</code>&lt;h1&gt;</code>-&lt;code &gt;</code>&lt;h6&gt;</code>) and wrap the sections up with &lt;code &gt;</code>&lt;section&gt;</code> (and the other new section elements) and have it be correct markup. Basically, allowing authors to replace &lt;code &gt;</code>&lt;div class="section"&gt;</code> with &lt;code &gt;</code>&lt;section&gt;</code>, &lt;code &gt;</code>&lt;div class="post"&gt;</code> with &lt;code &gt;</code>&lt;article&gt;</code>, etc.</li>
<li>It has to be possible to write new documents that use the section elements and have the headers be automatically styled to the right depth (and maybe automatically numbered, with appropriate CSS), and yet still be readable in legacy UAs, without having to think about old UAs. Basically, the header element has to be header-like in old browsers.</li>
<li>It shouldn't be too easy to end up with meaningless markup when doing either of the above. So a random &lt;code &gt;</code>&lt;h4&gt;</code> in the middle of an &lt;code &gt;</code>&lt;h2&gt;</code> and an &lt;code &gt;</code>&lt;h3&gt;</code> has to be defined as meaning _something_.</li>
</ol>
<p>At the moment what I'm thinking of doing is this (most of these ideas are in the draft at the moment, but mostly in contradictory ways):</p>
<p>The section elements would be:</p>
<blockquote>
<p>&lt;code &gt;</code>&lt;body&gt;</code> &lt;code &gt;</code>&lt;section&gt;</code> &lt;code &gt;</code>&lt;article&gt;</code> &lt;code &gt;</code>&lt;navigation&gt;</code> &lt;code &gt;</code>&lt;sidebar&gt;</code></p>
</blockquote>
<p>The header elements would be:</p>
<blockquote>
<p>&lt;code &gt;</code>&lt;header&gt;</code> &lt;code &gt;</code>&lt;h1&gt;</code> &lt;code &gt;</code>&lt;h2&gt;</code> &lt;code &gt;</code>&lt;h3&gt;</code> &lt;code &gt;</code>&lt;h4&gt;</code> &lt;code &gt;</code>&lt;h5&gt;</code> &lt;code &gt;</code>&lt;h6&gt;</code></p>
</blockquote>
<p>&lt;code &gt;</code>&lt;h1&gt;</code> gives the heading of the current section.</p>
<p>&lt;code &gt;</code>&lt;header&gt;</code> wraps block-level content to mark the whole thing as a header, so that you can have, e.g., subtitles, or "Welcome to" paragraphs before a header, or "Presented by" kind of information. &lt;code &gt;</code>&lt;header&gt;</code> is equivalent to an &lt;code &gt;</code>&lt;h1&gt;</code>. The first highest-level header in the &lt;code &gt;</code>&lt;header&gt;</code> is the "title" of the section for outlining purposes.</p>
<p>&lt;code &gt;</code>&lt;h2&gt;</code> to &lt;code &gt;</code>&lt;h6&gt;</code> are subsection headings when used in &lt;code &gt;</code>&lt;body&gt;</code>, and equivalent to &lt;code &gt;</code>&lt;h1&gt;</code> when used in one of the section elements.</p>
<p>&lt;code &gt;</code>&lt;h1&gt;</code> automatically sizes to fit the current nesting depth. This could be a problem in CSS since CSS can't handle this kind of thing well -- it has no "or" operator at the simple selector level.</p>
<p>&lt;code &gt;</code>&lt;h2&gt;</code>-&lt;code &gt;</code>&lt;h6&gt;</code> keep their legacy renderings for compatibility.</p>
</blockquote>

<p>Further discussion:</p>

<ul>
<li>August 2004: <a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2004-August/thread.html#1989">&lt;section&gt; and headings</a></li>
<li>September 2004: <a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2004-September/thread.html#2188">&lt;section&gt; and headings</a></li>
<li>November 2004: <a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2004-November/thread.html#2443">The Section Header Problem</a></li>
<li>March 2005: <a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2005-March/thread.html#3333">&lt;h1&gt; to &lt;h6&gt; in &lt;body&gt;</a></li>
<li>April 2005: <a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2005-April/thread.html#3377">&lt;section&gt;and headings and other threads</a>
</li></ul>

<p>Fast-forward to modern times.  Using the <code>&lt;section&gt;</code> element instead of, say, <code>&lt;div class="section"&gt;</code>, seems like a no-brainer.  Unfortunately, there's a catch.  (Hey, it's the web; there's always a catch.)  Not all modern browsers recognize the <code>&lt;section&gt;</code> element, which means that they fall back to their default handling of unknown elements.</p>

<h3>A long digression into browsers' handling of unknown elements</h3>

<p>Every browser has a master list of HTML elements that it supports.  For example, Mozilla Firefox's list is stored in <a href="http://mxr.mozilla.org/seamonkey/source/parser/htmlparser/src/nsElementTable.cpp">nsElementTable.cpp</a>.  Elements not in this list are treated as "unknown elements."  There are two fundamental problems with unknown elements:</p>

<ol>
<li><b>How should the element be styled?</b>  By default, <code>&lt;p&gt;</code> has spacing on the top and bottom, <code>&lt;blockquote&gt;</code> is indented with a left margin, and <code>&lt;h1&gt;</code> is displayed in a larger font.</li>
<li><b>What should the element's DOM look like?</b>  Mozilla's <code>nsElementTable.cpp</code> includes information about what kinds of other elements each element can contain.  If you include markup like <code>&lt;p&gt;&lt;p&gt;</code>, the second paragraph element implicitly closes the first one, so the elements end up as siblings, not parent-and-child.  But if you write <code>&lt;p&gt;&lt;span&gt;</code>, the <code>span</code> does not close the paragraph, because Firefox knows that <code>&lt;p&gt;</code> is a block element that can contain the inline element <code>&lt;span&gt;</code>.  So the <code>&lt;span&gt;</code> ends up as a child of the <code>&lt;p&gt;</code> in the DOM.</li>
</ol>

<p>Different browsers answer these questions in different ways.  (Shocking, I know.)  Of the major browsers, Microsoft Internet Explorer's answer to both questions is the most problematic.</p>

<p>The first question should be relatively simple to answer: don't give any special styling to unknown elements.  Just let them inherit whatever CSS properties are in effect wherever they appear on the page, and let the page author specify all styling with CSS.  Unfortunately, Internet Explorer does not allow styling on unknown elements.  For example, if you had this markup:</p>

<blockquote><pre><code>&lt;style type="text/css"&gt;
  section { border: 1px solid red }
&lt;/style&gt;
...
&lt;section&gt;
&lt;h1&gt;Welcome to Initech&lt;/h1&gt;
&lt;p&gt;This is our &lt;span&gt;home page&lt;/span&gt;.&lt;/p&gt;
&lt;/section&gt;</code></pre></blockquote>

<p>Internet Explorer (up to and including IE8 beta 2) will not put a red border around the section.</p>

<p>The second problem is the DOM that browsers create when they encounter unknown elements.  Again, the most problematic browser is Internet Explorer.  If IE doesn't explicitly recognize the element name, it will insert the element into the DOM <em>as an empty node with no children</em>.  All the elements that you would expect to be direct children of the unknown element will actually be inserted as siblings instead.  I've posted <a href="http://code.google.com/p/doctype/wiki/SectionElement">an ASCII graph that illustrates this mismatch</a>.</p>

<p>Sjoerd Visscher discovered a workaround for this problem: after you <a href="http://xopus.com/devblog/2008/style-unknown-elements.html">create a dummy element with that name</a>, IE will recognize the element enough to let you style it with CSS.  You can put the script in the <code>&lt;head&gt;</code> of your page, and there is no need to ever insert it into the DOM.  Simply creating the element once (per page) is enough to teach IE to style the element it doesn't recognize.  Sample code and markup:</p>

<blockquote><pre><code>&lt;html&gt;
&lt;head&gt;
&lt;style type="text/css"&gt;
  section { display: block; border: 1px solid red }
&lt;/style&gt;
<b>&lt;script type="text/javascript"&gt;
  document.createElement("section");
&lt;/script&gt;</b>
&lt;/head&gt;
&lt;body&gt;
&lt;section&gt;
&lt;h1&gt;Welcome to Initech&lt;/h1&gt;
&lt;p&gt;This is our &lt;span&gt;home page&lt;/span&gt;.&lt;/p&gt;
&lt;/section&gt;
&lt;/body&gt;
&lt;/html&gt;</code></pre></blockquote>

<p>This hack works in IE 6, IE 7, and IE 8 beta 1, but it doesn't work in IE 8 beta 2.  (<a href="http://connect.microsoft.com/IE/feedback/ViewFeedback.aspx?FeedbackID=364356">bug report</a>, <a href="http://philip.html5.org/tests/ie8/cases/unknown-element-styling.html">test case</a>)  The purpose of this illustration is not to blame IE; there's no specification that says what the DOM ought to look like in this case, so IE's handling of the "unknown element" problem is not any more or less correct than any other browser.  With the <code>createElement</code> workaround, you can use the <code>&lt;section&gt;</code> element (or any other new HTML 5 element) in all browsers except IE 8 beta 2.  I am not aware of any workaround for this problem.</p>

<h3>And in conclusion</h3>

<p>The <code>&lt;section&gt;</code> element is a very straightforward HTML 5 feature that you can't actually use yet.</p>
<p></p><p>This item was originally posted at: <a href='http://blog.whatwg.org'>http://blog.whatwg.org</a> and is licensed under the <a href='http://www.opensource.org/licenses/mit-license.php'>MIT license</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.htmlfive.net/the-road-to-html-5-episode-1-the-section-element/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
