<?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>HTML5 Doctor &#187; Mike Robinson</title>
	<atom:link href="http://html5doctor.com/author/miker/feed/" rel="self" type="application/rss+xml" />
	<link>http://html5doctor.com</link>
	<description>helping you implement HTML5 today</description>
	<lastBuildDate>Wed, 01 Feb 2012 09:28:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Pushing and Popping with the History API</title>
		<link>http://html5doctor.com/history-api/</link>
		<comments>http://html5doctor.com/history-api/#comments</comments>
		<pubDate>Tue, 15 Nov 2011 13:09:47 +0000</pubDate>
		<dc:creator>Mike Robinson</dc:creator>
				<category><![CDATA[JavaScript APIs]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[history]]></category>
		<category><![CDATA[HTML 5]]></category>
		<category><![CDATA[html5]]></category>

		<guid isPermaLink="false">http://html5doctor.com/?p=3897</guid>
		<description><![CDATA[Until recently, we developers couldn’t to do much with the state and history of the browser. We could check the number of items in the history and push users forwards and backwards, but this provides little benefit to the user. With the rise of more dynamic web pages, we need more control. Thankfully, HTML5 gives [...]]]></description>
			<content:encoded><![CDATA[<p>Until recently, we developers couldn’t to do much with the state and history of the browser. We could check the number of items in the history and push users forwards and backwards, but this provides little benefit to the user. With the rise of more dynamic web pages, we need more control. Thankfully, HTML5 gives us that control by extending the JavaScript History API.</p>
<section id="the-point">
<h2>What’s the point? <a class="permalink" href="#the-point">#</a></h2>
<p>It goes without saying that URLs are important. They’re <em>the</em> method of accessing the vast collections of information and resources on the web, and more recently, they’ve begun representing the intended state of a web application. You can copy these URLs and share them with your friends or use them to create links from any HTML document. They’re the veins of the web, and they need to be looked after.</p>
<p>Previously, the JavaScript History API offered some very simple functionality:</p>
<pre><code>// Check the length of the history stack
console.log(history.length);

// Send the user agent forward
console.log(history.forward());

// Send the user agent back
console.log(history.back());

// Send the user agent back (negative) or forward (positive)
// by a given number of items
console.log(history.go(-3));
</code></pre>
<p>With dynamic Ajax web applications, where the browser updates the page in parts instead of changing location entirely, it’s difficult to give the user a URL to bookmark or share the current application state. <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#the-id-attribute">Fragment identifiers</a>, like those used on this article’s headings via the <code>id</code> attribute, provide some state information, but they’re entirely dependent on client-side scripts.</p>
<p>The changes to the <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html">History API</a> are intended to give developers ways to push history items to the browser so the native back and forward actions can cycle through those items. These history items can also hold data that you can later extract to restore the page state.</p>
<blockquote>
<p>Pages can <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#dom-history-pushstate" title="dom-history-pushState">add</a> <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#state-object" title="state object">state objects</a> between their entry in the session history and the next (“forward”) entry. These are then <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#event-popstate" title="event-popstate">returned to the script</a> when the user (or script) goes back in the history, thus enabling authors to use the “navigation” metaphor even in one-page applications.</p>
<footer>- <cite><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html" title="6.4 Session history and navigation">WHATWG</a></cite></footer>
</blockquote>
<p>If the user copies or bookmarks a stateful URL and visits it later, your back-end can be configured to interpret such a URL and jump the user right to the correct page and/or state.</p>
<p>In this article, I’ll cover the client-side use of the History API, so make sure you set up your server to work with the new URLs. If you’ve already built an accessible website that provide these entry points, you’re laughing!</p>
<section id="those-fking-hashbangs">
<h4>Those <em>f#!king</em> hashbangs… <a class="permalink" href="#those-fking-hashbangs">#</a></h4>
<p>You may have already seen articles fussing over the adoption of the “hashbang” (#!) pattern on sites like <a href="http://twitter.com">Twitter</a>. This technique updates the address bar with a fragment identifier that can then be used by JavaScript to determine which page and state should be displayed.</p>
<p>This works as a method of creating a bookmarkable, shareable URL for a page’s state in the absense of a standard API. While the Twitter implementation accepts both <code>http://twitter.com/#!/akamike</code> and <code>http://twitter.com/akamike</code>, it has some disadvantages:</p>
<ul>
<li>The fragment identifier is only accessible on the client side. This means that only JavaScript can utilise it, so browsers without JavaScript enabled are out of luck.</li>
<li>As the server does not receive the path following the hashbang, removing that JavaScript drops support for all those URLs. That’s a lot of broken links, so you’re stuck with that JavaScript <em>forever</em>.</li>
<li>It’s ugly. It’s a hack and it looks like one.</li>
</ul>
<p>The hashbang was never intended to be a long-term solution, so don’t rely on it. If you do use hashbangs, be prepared to deal with the consequences (and possible backlash from web purists).</p>
</section>
</section>
<section id="making-history">
<h2>Making History <a class="permalink" href="#making-history">#</a></h2>
<p>These examples will build on top of each other. We’ll start with a <a href="http://html5doctor.com/wp-content/uploads/2011/10/history_base.html">basic HTML document</a> with some inline styles and scripts for your convenience.</p>
<aside class="sidenote">
<p>For a simple HTTP server, open the command line, <code>cd</code> to the directory you would like to serve, run <code>python -m SimpleHTTPServer 8080</code>, then open <code>localhost:8080</code> in your browser. Alternatively, try a bundled setup like <a href="http://www.apachefriends.org/en/xampp.html">XAMPP</a> or <a href="http://www.mamp.info/en/index.html">MAMP</a>.</p>
</aside>
<p>Save this file and open it in your favourite editor. It must be accessed via HTTP, so that means you need either a local server (e.g. <code>http://localhost/</code>) or an online web server you can upload to. <strong>Viewing the file directly using your browser’s Open File function will not work</strong>, since it uses the <code>file://</code> protocol and not HTTP. Also be sure to update the <code>href</code> attributes on each of the navigation links to ensure the correct directory structure is used. Personally, I’m viewing the demo locally at <code>http://localhost/history</code>.</p>
<p>We’ll be working exclusively within the <code>&lt;script&gt;</code> element at the end of the <code>&lt;body&gt;</code>. The code includes some simple styles and dynamically changes the content as you click the links. In reality, this could be loaded from your server via <code>XMLHttpRequest</code>, but for the purposes of this demonstration I’ve bundled it up into a self-contained file. The important part is that we have a quick-and-dirty dynamic page to work with, so let the fun begin!</p>
<p>At the moment there, is no bookmarkable URL for the different states of this page. If you click around the navigation items, then click Back in your browser, you won’t be taken back to the previous state and may even be taken away from the page to whatever you viewed before (depending on your browser). It would be nice if you could share “Socks” with your friends, right? We can do that via <code>history.pushState()</code>.</p>
<p>The <code>history.pushState()</code> method takes three parameters:</p>
<dl>
<dt><code>data</code></dt>
<dd>Some structured data, such as settings or content, assigned to the history item.</dd>
<dt><code>title</code></dt>
<dd>The name of the item in the history drop-down shown by the browser’s back and forward buttons. (Note: this is not currently supported by any major browsers.)</dd>
<dt><code>url</code> <em>(optional)</em></dt>
<dd>The URL to this state that should be displayed in the address bar.</dd>
</dl>
<p>With these parameters, you can define the state of the page, give that state a name, and even provide a bookmarkable address, as if the page had reloaded entirely. Let’s dive right in and add this to the <code>clickHandler</code> function, right above the <code>return</code> statement:</p>
<figure>
<pre><code>function clickHandler(e) {
  /* Snip... */

  // Add an item to the history log
  history.pushState(data, event.target.textContent, event.target.href);

  return event.preventDefault();
}
</code></pre>
</figure>
<p>The single line of code we added informs the <code>history</code> object that:</p>
<ul>
<li>we want to add an item to the log,</li>
<li>it should remember the data that we’ve already loaded,</li>
<li>it should assign a name to this state based on the text of the link we clicked (even though this isn’t used — it’s good to get into the habit of recording a name for the state), and</li>
<li>it should update the address bar with the <code>href</code> attribute of that link.</li>
</ul>
<p>Reload the page in your browser and click a few of the links, keeping an eye on the address bar. Notice how it changes on each click, despite the fact that you aren’t actually navigating away from this page. If you also have a look at your history log, you’ll see a long list of page titles (in this case ”Kittens!” over and over). Provided your server is set up to serve the correct page upon access, the user could copy that URL and paste it into a new browser window to jump straight to that kitten.</p>
<p>At the moment, clicking the back button will pop you through the history items, but the page won’t react to these changes. That&#8217;s because so far, we’ve only created the history records. How can we allow active users to return to a previous state? We listen to the <code>popstate</code> event.</p>
</section>
<section id="historical-events">
<h2>Historical Events in Navigation <a class="permalink" href="#historical-events">#</a></h2>
<p>The user agent fires a <code>popstate</code> event when the user navigates through their history, whether backwards or forwards, provided it isn’t taking the user away from the current page. That is, all those <code>pushState</code>s we called will keep the user on the current page, so the <code>popstate</code> event will fire for each history item they pop through.</p>
<p>Before the closing <code>&lt;/script&gt;</code> tag, add a new listener for the <code>popstate</code> event:</p>
<figure>
<pre><code>// Revert to a previously saved state
window.addEventListener('popstate', function(event) {
  console.log('popstate fired!');

  updateContent(event.state);
});
</code></pre>
</figure>
<p>We attach the event listener to the <code>window</code>, which is responsible for firing the event, and pass this event into our handler. We log a message (so we can see when this event is firing), and then we update the content using the state we saved previously. The state is attached to the <code>event</code> object via the <code>state</code> property.</p>
<p>Open up the page fresh in your browser, click around like before, and then click back. As before, the URL in the address bar changes as you cycle through states, but now the content is also restored back to what it should be. Click forward, and the content is likewise correctly restored.</p>
<div class="callout warning-block">
<p>If you look at the developer console in Chrome when you load the page for the first time, you’ll see the <code>popstate</code> event fired immediately, before you’ve even clicked a link. This is because Chrome considers the initial page load to be a change in state, and so it fires the event. In this instance, the <code>state</code> property is <code>null</code>, but thankfully the <code>updateContent</code> function deals with this. Keep this in mind when developing as it could catch you out, especially if other browsers assume this behavior.</p>
</p></div>
</section>
<section id="rewriting-history">
<h2>Rewriting history <a class="permalink" href="#rewriting-history">#</a></h2>
<p>Unfortunately, as fantastic as HTML5 is, it doesn’t allow us actual time travel. If it did, I would be going back to my childhood and telling a younger me, “Yes, you should have a slice of cake”. Take that as you will.</p>
<p>The History API does, however, allow us to make amends to our history log items. For example, we could update the current state in response to fresh user input in a form. We can do this with <code>history.replaceState</code>.</p>
<p><code>replaceState</code> works just as <code>pushState</code> does, with the exact same parameters, except that it updates the current entry instead of adding a new one. I can think of one situation in our demo where this could be used: the initial page load. If you click back for long enough, you’ll find that going back to the original URL doesn’t provide you the original content. Let’s fix that by adding the following to the bottom of our script:</p>
<figure>
<pre><code>// Store the initial content so we can revisit it later
history.replaceState({
  content: contentEl.textContent,
  photo: photoEl.src
}, document.title, document.location.href);
</code></pre>
</figure>
<p>As this runs when the page loads, it saves the initial page state. We can later load this state when the user browses back to this point via the event listener we set up previously. You can try it out by loading up the page, clicking a few links, and then hitting back until you return to the original URL. The initial content has returned!</p>
</section>
<section id="demo">
<h2>Demo <a class="permalink" href="#demo">#</a></h2>
<p>I’ve set up a demo of our completed code. I’ve also added a little back-end magic to make our <code>history.pushState</code> URLs work like a real site. Remember that the URLs you push should be live URLs that the user can bookmark and share as real entry points to your site.</p>
<p class="btn half"><a href="http://html5doctor.com/demos/history/">View the History API demo</a></p>
</section>
<section id="browser-support">
<h2>Browser support <a class="permalink" href="#browser-support">#</a></h2>
<p>Up-to-date copies of Chrome (5+), Safari (5.0+), Firefox (4.0+), and Opera (11.50+) have support for the new History API. Even some mobile browsers work just fine, like Mobile Safari on iOS 4+. Unfortunately, IE 9 and below lack support, but it <a href="http://msdn.microsoft.com/en-us/ie/hh272905.aspx#_HTML5History">should work in IE 10</a> when it arrives.</p>
<p>Safari 5.0 sometimes exhibits one oddity: navigating between states causes the loading spinner to appear and stay even when the state has been loaded. This stops when you navigate away using a link or action that does not involve a state saved by the History API.</p>
<section id="polyfill">
<h3>Polyfill <a class="permalink" href="#polyfill">#</a></h3>
<p>A polyfill does exist for the History API. The aptly named <a href="https://github.com/balupton/history.js">History.js</a> uses HTML4’s <code>hashchange</code> event with document fragment identifiers to mimic the history API in older browsers. If one of the hash URLs is used by a modern browser, it uses <code>replaceState</code> to quietly correct the URL.</p>
<p>It sounds like magic, but make sure you’re aware of the consequences of using fragment identifiers, as mentioned previously in this article. As such, the author of History.js has put together a guide titled <a href="https://github.com/balupton/history.js/wiki/Intelligent-State-Handling">Intelligent State Handling</a>.</p>
</section>
</section>
<section id="closing">
<h2>Closing thoughts <a class="permalink" href="#closing">#</a></h2>
<p>URLs go beyond just the browsing session of a user. They’re historically important markers for resources that could very well remain in use for many years to come. Before you embark on developing your site’s JavaScript, you should give thought to the <a href="http://warpspire.com/posts/url-design/">design of your URLs</a>. Make them meaningful and organised. Make sure you can directly access them without JavaScript. Only then should you add your JavaScript to enhance the browsing experience.</p>
</section>
<div id="crp_related">
<h3>Related Posts:</h3>
<ul class="related">
<li><a href="http://html5doctor.com/server-sent-events/" rel="bookmark" class="crp_title">Server-Sent Events</a></li>
<li><a href="http://html5doctor.com/how-to-get-all-the-browsers-playing-ball/" rel="bookmark" class="crp_title">How to get all the browsers playing ball</a></li>
<li><a href="http://html5doctor.com/methods-of-communication/" rel="bookmark" class="crp_title">Methods of communication</a></li>
<li><a href="http://html5doctor.com/storing-data-the-simple-html5-way-and-a-few-tricks-you-might-not-have-known/" rel="bookmark" class="crp_title">Storing Data the Simple HTML5 Way (and a few tricks you might not have known)</a></li>
<li><a href="http://html5doctor.com/native-drag-and-drop/" rel="bookmark" class="crp_title">Native Drag and Drop</a></li>
</ul>
</div>
<p><a href="http://html5doctor.com/history-api/" rel="bookmark">Pushing and Popping with the History API</a> originally appeared on <a href="http://html5doctor.com">HTML5 Doctor</a> on November 15, 2011.</p>
]]></content:encoded>
			<wfw:commentRss>http://html5doctor.com/history-api/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Document Outlines</title>
		<link>http://html5doctor.com/outlines/</link>
		<comments>http://html5doctor.com/outlines/#comments</comments>
		<pubDate>Tue, 12 Jul 2011 14:57:06 +0000</pubDate>
		<dc:creator>Mike Robinson</dc:creator>
				<category><![CDATA[Structure]]></category>
		<category><![CDATA[HTML 5]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[outline]]></category>

		<guid isPermaLink="false">http://html5doctor.com/?p=3433</guid>
		<description><![CDATA[<p>Document outlines have changed a bit in HTML5. For a start, they’re actually in the spec! The HTML5 Doctor is here to explain what document outlines are, how to make good ones, and why you should care.</p>]]></description>
			<content:encoded><![CDATA[<p>Document outlines have changed a bit in HTML5. For a start, they’re actually in the spec! The HTML5 Doctor is here to explain what document outlines are, how to make good ones, and why you should care.</p>

<section id="what-are-outlines">
  <h2>What are document outlines? <a class="permalink" href="#what-are-outlines">#</a></h2>
  
  <p>The document outline is the structure of a document, generated by the document’s headings, form titles, table titles, and any other appropriate landmarks to <a href="http://www.w3.org/TR/2002/REC-UAAG10-20021217/guidelines#tech-provide-outline-view">map out the document</a>. The user agent can apply this information to generate a table of contents, for example. This table of contents could then be used by assistive technology to help the user, or be parsed by a machine like a search engine to improve search results.</p>
  
  <p>The outlining algorithm has been clearly defined in the <a href="http://dev.w3.org/html5/spec/Overview.html#outlines">HTML5 spec</a>, so once all browsers and assistive technologies play ball, there will be some major accessibility wins (more on <a href="#real-world-outlines">support</a> later). Before we take a look at how this new algorithm works, it’s time for a quick walk down memory lane.</p>
</section>

<section id="outlines-in-html4">
  <h2>Outlines in HTML4 <a class="permalink" href="#outlines-in-html4">#</a></h2>
  
  <p>Creating document outlines prior to HTML5 was simple. You had six heading elements, <code>&lt;h1&gt;</code> through <code>&lt;h6&gt;</code>. Lower-numbered headings were of a higher rank of higher-numbered ones — i.e. <code>&lt;h1&gt;</code> was ranked higher than <code>&lt;h2&gt;</code>:</p>

  <pre><code>&lt;h1&gt;My fantastic site&lt;/h1&gt;
&lt;h2&gt;About me&lt;/h2&gt;
&lt;p&gt;I am a man who lives a fascinating life. Oh the stories I could tell you...&lt;/p&gt;
&lt;h3&gt;What I do for a living&lt;/h3&gt;
&lt;p&gt;I sell enterprise-managed ant farms.&lt;/p&gt;
&lt;h2&gt;Contact&lt;/h2&gt;
&lt;p&gt;Shout my name and I will come to you.&lt;/p&gt;
</code></pre>

  <p>This example would produce the following outline:</p>
  <div class="callout">
  <ol>
    <li>
      My fantastic site
      <ol>
        <li>
          About me
          <ol>
            <li>What I do for a living</li>
          </ol>
        </li>
        <li>Contact</li>
      </ol>
    </li>
  </ol>
</div>

  <p>The <code>&lt;h2&gt;</code> titles are children of the <code>&lt;h1&gt;</code>, and the &#8220;About me&#8221; content has a further sub-heading using an <code>&lt;h3&gt;</code>. It’s simple but restrictive, as you have to ensure the heading levels are appropriate for the intended structure, and you’re limited to six levels. The latter restriction is usually not such a problem, but it still exists for all you heading fanatics (oh you guys!).</p>

  <p>HTML5 does this as well. The above example would produce the same outline, but it can be taken even further using the new sectioning elements.</p>
</section>

<section id="sectioning-elements">
  <h2>Sectioning elements <a class="permalink" href="#sectioning-elements">#</a></h2>
  
  <p>The concepts behind HTML5 document outlines are actually older than you might think! Tim Berners-Lee posted to the www-talk mailing list <a href="http://lists.w3.org/Archives/Public/www-talk/1991SepOct/0003.html">back in 1991</a> (props to <a href="http://html5doctor.com/author/olib/">Dr Oli</a> for digging that up), suggesting something quite close to what is demonstrated in this article.</p>

  <p>The sectioning elements <a href="/section/"><code>&lt;section&gt;</code></a>, <a href="/article/"><code>&lt;article&gt;</code></a>, <a href="/aside/"><code>&lt;aside&gt;</code></a> and <a href="/nav/"><code>&lt;nav&gt;</code></a> can all help to create a more logical structure in the document outline. Let&#8217;s go crazy and rewrite our previous example using only <code>&lt;h1&gt;</code> elements for headings:</p>

  <pre><code>&lt;h1&gt;My fantastic site&lt;/h1&gt;
&lt;h1&gt;About me&lt;/h1&gt;
&lt;p&gt;I am a man who lives a fascinating life. Oh the stories I could tell you...&lt;/p&gt;
&lt;h1&gt;What I do for a living&lt;/h1&gt;
&lt;p&gt;I sell enterprise-managed ant farms.&lt;/p&gt;
&lt;h1&gt;Contact&lt;/h1&gt;
&lt;p&gt;Shout my name and I will come to you.&lt;/p&gt;
</code></pre>

  <p>The outline would now look like this:</p>
<div class="callout">
  <ol>
    <li>My fantastic site</li>
    <li>About me</li>
    <li>What I do for a living</li>
    <li>Contact</li>
  </ol>
</div>
  <p>Clearly, that’s no good — we&#8217;ve lost our structure! With sectioning elements, we can make it look like before without changing those headings. In this particular example, I think <code>&lt;section&gt;</code> is most appropriate:</p>

  <pre><code>&lt;h1&gt;My fantastic site&lt;/h1&gt;
&lt;section&gt;
  &lt;h1&gt;About me&lt;/h1&gt;
  &lt;p&gt;I am a man who lives a fascinating life. Oh the stories I could tell you...&lt;/p&gt;
  &lt;section&gt;
    &lt;h1&gt;What I do for a living&lt;/h1&gt;
    &lt;p&gt;I sell enterprise-managed ant farms.&lt;/p&gt;
  &lt;/section&gt;
&lt;/section&gt;
&lt;section&gt;
  &lt;h1&gt;Contact&lt;/h1&gt;
  &lt;p&gt;Shout my name and I will come to you.&lt;/p&gt;
&lt;/section&gt;
</code></pre>

  <p>Run it through the outliner and we’re back to normal:</p>
<div class="callout">
  <ol>
    <li>
      My fantastic site
      <ol>
        <li>
          About me
          <ol>
            <li>What I do for a living</li>
          </ol>
        </li>
        <li>Contact</li>
      </ol>
    </li>
  </ol>
</div>
  <p>But why? The sectioning elements act quite literally as their name suggests: <em>they define sections of the parent element</em>. These sections can be thought of as child nodes whose headings fall under their parent heading, regardless of their rank. The following example illustrates this further:</p>

  <pre><code>&lt;h2&gt;HTML5 Doctor articles&lt;/h2&gt;
&lt;article&gt;
  &lt;h1&gt;The section element&lt;/h1&gt;
  &lt;p&gt;We doctors are a bunch of chums using HTML5 and writing about how we do it...&lt;/p&gt;
&lt;/article&gt;
&lt;article&gt;
  &lt;h1&gt;The article element&lt;/h1&gt;
  &lt;p&gt;We’ve discussed a lot of new elements here at HTML5Doctor...&lt;/p&gt;
&lt;/article&gt;
</code></pre>

  <p>Even though the articles contain <code>&lt;h1&gt;</code>s, this produces the following outline: </p>

<div class="callout">
  <ol>
    <li>
      HTML5 Doctor articles
      <ol>
        <li>The section element</li>
        <li>The article element</li>
      </ol>
    </li>
  </ol>
</div>  

  <p>Equally, owing to how the outliner works, the following examples
(while probably not the best use of headings) produce the exact same above outline:</p>
  
    <figure>
      <pre><code>&lt;h1&gt;HTML5 Doctor articles&lt;/h1&gt;
&lt;article&gt;
  &lt;h3&gt;The section element&lt;/h3&gt;
&lt;/article&gt;
&lt;article&gt;
  &lt;h3&gt;The article element&lt;/h3&gt;
&lt;/article&gt;
</code></pre>
    </figure>
  
  <figure>
    <pre><code>&lt;h2&gt;HTML5 Doctor articles&lt;/h2&gt;
&lt;article&gt;
  &lt;h2&gt;The section element&lt;/h2&gt;
&lt;/article&gt;
&lt;article&gt;
  &lt;h2&gt;The article element&lt;/h2&gt;
&lt;/article&gt;
</code></pre>
  </figure>

  <figure>
    <pre><code>&lt;h6&gt;HTML5 Doctor articles&lt;/h6&gt;
&lt;article&gt;
  &lt;h1&gt;The section element&lt;/h1&gt;
&lt;/article&gt;
&lt;article&gt;
  &lt;h1&gt;The article element&lt;/h1&gt;
&lt;/article&gt;
</code></pre>
  </figure>
  
  <p>When choosing which heading to use in your documents, <a href="http://www.whatwg.org/specs/web-apps/current-work/complete/sections.html#headings-and-sections">the spec</a> has recommendations:</p>

<blockquote cite="http://www.whatwg.org/specs/web-apps/current-work/complete/sections.html#headings-and-sections">
<p>Sections may contain headings of any rank, but authors are strongly encouraged to either use only h1 elements, or to use elements of the appropriate rank for the section’s nesting level.</p>
<footer>— <cite><a href="http://www.whatwg.org/specs/web-apps/current-work/complete/sections.html#headings-and-sections" title="4.4.11 Headings and sections">WHATWG HTML5 specification</a></cite></footer></blockquote>

  <p>You should also make sure you’re aware of how differently ranked headings work when used as direct children of a sectioning element. It&#8217;s how it worked prior to HTML5:</p>

  <blockquote cite="http://www.whatwg.org/specs/web-apps/current-work/complete/sections.html#headings-and-sections"><p>The first element of heading content in an element of sectioning content represents the heading for that section. Subsequent headings of equal or higher rank start new (implied) sections, headings of lower rank start implied subsections that are part of the previous one. In both cases, the element represents the heading of the implied section.</p>
<footer>— <cite><a href="http://www.whatwg.org/specs/web-apps/current-work/complete/sections.html#headings-and-sections" title="4.4.11 Headings and sections">WHATWG HTML5 specification</a></cite></footer></blockquote>

  <section id="untitled-sections">
    <h3>Untitled sections <a class="permalink" href="#untitled-sections">#</a></h3>

    <p>Sectioning elements that do not contain a child heading will be labelled as “Untitled”, indicating the lack of a logical heading but preserving the outline as in the example below:</p>
    
    <figure>
      <pre><code>&lt;aside&gt;
  &lt;section&gt;
    &lt;h2&gt;Twitter&lt;/h2&gt;
  &lt;/section&gt;
  &lt;section&gt;
    &lt;h2&gt;Recent comments&lt;/h2&gt;
  &lt;/section&gt;
&lt;/aside&gt;
</code></pre>
    </figure>
    
    <p>Running this through the outliner produces this outline:</p>
    <div class="callout">
    <ol>
      <li>
        Untitled <code>aside</code>
        <ol>
          <li>Twitter</li>
          <li>Recent comments</li>
        </ol>
      </li>
    </ol>
    </div>
    
    <p>The outliner has taken the liberty of flagging the sectioning element as untitled, to act as a warning and to preserve a logical structure. For accessibility reasons, we recommend each sectioning element have a heading, even <code>&lt;aside&gt;</code> and <code>&lt;nav&gt;</code>, as shown below. If you don’t want these headings to be visible, you can always hide them with CSS.</p>

    <figure>
      <pre><code>&lt;aside&gt;
  &lt;h1&gt;What you're saying&lt;/h1&gt;
  &lt;section&gt;
    &lt;h2&gt;Twitter&lt;/h2&gt;
  &lt;/section&gt;
  &lt;section&gt;
    &lt;h2&gt;Recent comments&lt;/h2&gt;
  &lt;/section&gt;
&lt;/aside&gt;
</code></pre>
    </figure>

<p>Remember, elements like <code>&lt;section&gt;</code> should not be used arbitrarily. See our <a href="http://html5doctor.com/the-section-element/">section article</a> for more.</p>
  </section>
</section>

<section id="using-hgroup">
  <h2>How does <code>&lt;hgroup&gt;</code> affect the outline? <a class="permalink" href="#using-hgroup">#</a></h2>
  
  <p>As Dr Richard Clark said in <a href="http://html5doctor.com/the-hgroup-element/">our <code>&lt;hgroup&gt;</code> article</a>, <code>&lt;hgroup&gt;</code> is <q cite="http://html5doctor.com/the-hgroup-element/">all about the document outline</q>. The outliner will disregard all headings within <code>&lt;hgroup&gt;</code> except the one with the highest ranking. For example, if an <code>&lt;hgroup&gt;</code> contains an <code>&lt;h2&gt;</code>, an <code>&lt;h3&gt;</code> and an <code>&lt;h4&gt;</code>, only the <code>&lt;h2&gt;</code>’s text will be used as the section title in the outline. For example, the following markup:</p>

<pre><code>&lt;article&gt;
  &lt;hgroup&gt;
    &lt;h1&gt;Title goes here&lt;/h1&gt;
    &lt;h2&gt;Subtitle of article&lt;/h2&gt;
  &lt;/hgroup&gt;
  &lt;p&gt;Lorem Ipsum dolor set amet&lt;/p&gt;
&lt;/article&gt;</code></pre>

<p>Would produce the following outline.</p>

    <div class="callout">
    <ol>
      <li>Title goes here</li>
    </ol>
    </div>

  <p>At the time of writing, <code>&lt;hgroup&gt;</code>&#8217;s future is a little uncertain. It was recently <a href="http://html5doctor.com/the-hgroup-hokey-cokey/">removed and then returned</a> to the HTML5 spec, and there are <a href="http://www.w3.org/html/wg/wiki/ChangeProposals/dropHgroup">proposals</a> for its removal or replacement with an alternative. We&#8217;ll be sure to keep HTML5 Doctor up-to-date with any changes as they unfold.</p>
</section>

<section id="sectioning-roots">
  <h2>Sectioning roots <a class="permalink" href="#sectioning-roots">#</a></h2>
  
  <p>Sectioning roots, introduced in HTML5, isolate certain parts of a document to their own separate outlines. Headings within these elements will not show up in the main outline, where the sectioning root element is the <code>&lt;body&gt;</code>.</p>

  <p>The other sectioning root elements are <code>&lt;blockquote&gt;</code>, <code>&lt;figure&gt;</code>, <code>&lt;details&gt;</code>, <code>&lt;fieldset&gt;</code>, and <code>&lt;td&gt;</code>. Each one of these elements is a descendant of the <code>&lt;body&gt;</code> element, but its headings are removed from the top-level outline, instead starting its own isolated outline.</p>
  
  <figure>
    <pre><code>&lt;h1&gt;Top of the outline&lt;/h1&gt;

&lt;section&gt;
  &lt;h2&gt;A heading in the outline&lt;/h2&gt;
  &lt;p&gt;Lorem ipsum dolor sit amet...&lt;/p&gt;
&lt;/section&gt;
&lt;section&gt;
  &lt;h2&gt;Another heading in the outline&lt;/h2&gt;
  &lt;p&gt;Lorem ipsum dolor sit amet...&lt;/p&gt;
  &lt;blockquote&gt;
    &lt;h1&gt;This quoted heading will not appear in the outline&lt;/h1&gt;
    &lt;p&gt;Lorem ipsum dolor sit amet...&lt;/p&gt;
  &lt;/blockquote&gt;
&lt;/section&gt;
</code></pre>
  </figure>
  
  <p>This results in the following outline. Notice that it lacks the <code>&lt;blockquote&gt;</code>’s heading, which has been isolated:</p>
<div class="callout">
  <ol>
    <li>
      Top of the outline
      <ol>
        <li>A heading in the outline</li>
        <li>Another heading in the outline</li>
      </ol>
    </li>
  </ol>
</div>
</section>

<section id="real-world-outlines">
  <h2>Outlines in the real world <a class="permalink" href="#real-world-outlines">#</a></h2>
    
  <p>Unfortunately, there is little support for the new outlining algorithms right now. Search engines may be experimenting with it in their crawling algorithms as you read this, but as far as we know, headings are treated just as they were before. You won’t be penalised for using them, even if you use <a href="http://www.youtube.com/watch?v=GIn5qJKU8VM">multiple <code>&lt;h1&gt;</code>s</a> (which have always been okay as far as the spec is concerned). Check out our <a href="http://html5doctor.com/html5-seo-search-engine-optimisation/">HTML5 and Search Engine Optimisation</a> article for more on search engines and HTML5.</p>
  
  <p>At the time of writing, screen readers do not support these new outlines, so if you do use multiple <code>&lt;h1&gt;</code>s in your documents, it may confuse your users. It’s best if you use logical heading levels — <code>&lt;h1&gt;</code>–<code>&lt;h6&gt;</code> — at least until the new outlines are more widely supported.</p>

  <p>As for browsers, both recent releases of Firefox and Chrome have a user agent styles that support HTML5 document outlines. Try this <a href="http://jsbin.com/ijixib">bare-bones example</a> in the latest Chrome or Firefox.</p>
</section>

<section id="conclusion">
  <h2>Final thoughts <a class="permalink" href="#conclusion">#</a></h2>
  
  <p>Despite the spotty support, it’s definitely worth thinking carefully about your document outlines so you’re prepared for the future, and tune in here for news of improved support.</p>
  
  <p>Get to grips with the sectioning elements and sectioning roots and how each affects the outline. When marking up a new site, consider how you could take advantage of the new document outline algorithm. As user agent support strengthens, pages you made with your new-found knowledge of document outlines will be more accessible. Let us know what you think in the comments below!</p>
  
  <section id="outliners">
    <h3>Outliner tools <a class="permalink" href="#outliners">#</a></h3>

    <p>In order to test your outlines, you’ll need an outliner. Here are a few options to get you started:</p>
    
    <ul>
      <li><a href="http://code.google.com/p/h5o/">h5o</a>, a Javascript implementation of the outliner, available as a bookmarklet, extension, or minified JavaScript file</li>
      <li><a href="https://addons.opera.com/addons/extensions/details/html5-outliner/1.0/">An Opera extension</a></li>
      <li><a href="http://gsnedders.html5.org/outliner/">An online outliner</a> where you can upload a file or submit a URL or HTML source to parse (may no longer be under development)</li>
    </ul>
  </section>
</section><div id="crp_related"><h3>Related Posts:</h3><ul class="related"><li><a href="http://html5doctor.com/the-hgroup-element/" rel="bookmark" class="crp_title">The hgroup element</a></li><li><a href="http://html5doctor.com/the-hgroup-hokey-cokey/" rel="bookmark" class="crp_title">The hgroup hokey cokey</a></li><li><a href="http://html5doctor.com/your-questions-5/" rel="bookmark" class="crp_title">Your Questions Answered #5</a></li><li><a href="http://html5doctor.com/your-questions-answered-6/" rel="bookmark" class="crp_title">Your Questions Answered #6</a></li><li><a href="http://html5doctor.com/the-section-element/" rel="bookmark" class="crp_title">The section element</a></li></ul></div><p><a href="http://html5doctor.com/outlines/" rel="bookmark">Document Outlines</a> originally appeared on <a href="http://html5doctor.com">HTML5 Doctor</a> on July 12, 2011.</p>
]]></content:encoded>
			<wfw:commentRss>http://html5doctor.com/outlines/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Go offline with application cache</title>
		<link>http://html5doctor.com/go-offline-with-application-cache/</link>
		<comments>http://html5doctor.com/go-offline-with-application-cache/#comments</comments>
		<pubDate>Tue, 25 Jan 2011 15:00:48 +0000</pubDate>
		<dc:creator>Mike Robinson</dc:creator>
				<category><![CDATA[JavaScript APIs]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[manifest]]></category>
		<category><![CDATA[offline]]></category>

		<guid isPermaLink="false">http://html5doctor.com/?p=2729</guid>
		<description><![CDATA[<p>HTML5 introduces new methods for enabling a web site or web application to function without a network connection. When you're working on a mobile connection and your signal drops, or you just have no connection to the internet for whatever reason, having some level of access is better than nothing. In this article, we'll look at how the application cache can store resources to be used by the browser when it's offline, granting your users partial access to your web site or application.</p>]]></description>
			<content:encoded><![CDATA[<p><abbr>HTML</abbr>5 introduces new methods for enabling a web site or web application to function without a network connection. When you&#8217;re working on a mobile connection and your signal drops, or you just have no connection to the internet for whatever reason, having some level of access is better than nothing. In this article, we&#8217;ll look at how the application cache can store resources to be used by the browser when it&#8217;s offline, granting your users partial access to your web site or application.</p>

<p>The <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/offline.html">application cache</a> is controlled by a plain text file called a manifest, which contains a list of resources to be stored for use when there is no network connectivity. The list can also define the conditions for caching, such as which pages should never be cached and even what to show the user when he follows a link to an uncached page.</p>

<p>If the user goes offline but has visited the site while online, the cached resources will be loaded so the user can still view the site in a limited form. By carefully considering the contents of your manifest file, you can offer a suitable web experience to a disconnected user.</p>

<section id="manifest">
  <h2>The manifest file</h2>
  <p>Let&#8217;s start with an example of a full manifest file. (Don&#8217;t worry, I&#8217;ll explain it all in detail!)</p>
  
  <figure>
    <pre><code>CACHE MANIFEST
      
# This is a comment

CACHE:
/css/screen.css
/css/offline.css
/js/screen.js
/img/logo.png

http://example.com/css/styles.css

FALLBACK:
/ /offline.html

NETWORK:
*
</code></pre>
    <figcaption>An example application cache manifest file</figcaption>
  </figure>
  
  <p>Each directive is placed on a new line, with comments prefixed by a hash (#). The first line, <code>CACHE MANIFEST</code>, tells the browser that this is a manifest file. The uppercased lines with trailing colons are section headings.</p>
  
  <p>There are three different sections in a manifest file:</p>
  
  <dl>
    <dt>CACHE</dt>
    <dd>A list of explicit <abbr>URL</abbr>s to request and store</dd>
    <dt>FALLBACK</dt>
    <dd>What to do when an offline user attempts to access an uncached file</dd>
    <dt>NETWORK</dt>
    <dd>Which resources are available only while online</dd>
  </dl>
  
  <p>Each section serves a specific purpose that you must understand in order to successfully and effectively cache your resources.</p>
  
  <section id="cache">
    <h3>CACHE</h3>
    <p>The <code>CACHE</code> section is considered the default — i.e., if no section heading has been defined, the browser will assume this is the <code>CACHE</code> section. Beneath this heading, you can list <abbr>URI</abbr>s to resources you want the browser to download and cache for offline use, including <abbr>URI</abbr>s hosted externally.</p>
  
    <figure>
      <pre><code>CACHE MANIFEST

/css/screen.css
/css/offline.css
/js/screen.js
/img/logo.png

http://example.com/css/widget.css</code></pre>

      <figcaption>Telling the browser to cache some stylesheets, an image, and a JavaScript file</figcaption>
    </figure>
  
    <p>In this example, I&#8217;ve omitted the <code>CACHE:</code> heading to take advantage of the default behaviour. I have provided the browser with four paths relative to the root of the domain plus one external resource. When the browser downloads the cache manifest file, it will read these five resources, fetch them over <abbr>HTTP</abbr>, and store them for later use.</p>
  
    <p>Every single resource that you want to cache explicitly should be listed here, right down to the last image. The browser is not aware of a resource unless you provide the full path to it. This means <strong>you can&#8217;t use wildcards</strong>. If you list <code>/images/*</code> as a resource, the browser will request that <abbr>URI</abbr> as if you typed it into your address bar.</p>
  
    <p>But don&#8217;t run off and shove <abbr>URI</abbr>s for every single page on your site into your manifest! When a user visits a page that points to the manifest file, that page will also be cached. This means that if you want to allow users access to pages they&#8217;ve already viewed, just make those pages point to the manifest file and the browser will cache them appropriately.</p>
  
    <p>Now let&#8217;s tell the browser what to do with uncached resources.</p>
  </section>
  
  <section id="fallback">
    <h3>FALLBACK</h3>
  
    <p>The <code>FALLBACK</code> section tells the browser what to serve when the user tries to access an uncached resource while offline. Because of this, it looks a bit different than <code>CACHE</code> and <code>NETWORK</code>. It contains two values per line, separated by a space. The first value is the request <abbr>URI</abbr> to match, and the second is the resource sent upon matching. It caches the resource on the right for offline use, so this should be an explicit path.</p>
    
    <p>Lost? Take a look at this example:</p>
  
    <figure>
      <pre><code>CACHE MANIFEST

FALLBACK:
/status.html /offline.html</code></pre>
      <figcaption>Declaring a <code>FALLBACK</code> section</figcaption>
    </figure>
  
    <p>On the line below <code>FALLBACK:</code>, we have the <abbr>URI</abbr> &#8220;/status.html&#8221; followed by a second <abbr>URI</abbr>, &#8220;/offline.html&#8221;. We&#8217;re telling the browser that when an offline user requests a <abbr>URI</abbr> matching &#8220;/status.html&#8221;, it should instead serve the cached file &#8220;offline.html&#8221;.</p>
    
    <p>However, the <code>FALLBACK</code> section can be far more powerful:</p>
  
    <figure>
      <pre><code>CACHE MANIFEST

FALLBACK:
/ /offline.html</code></pre>
      <figcaption>Matching all resources</figcaption>
    </figure>
  
    <p>In this example, I&#8217;ve dropped &#8220;status.html&#8221; and simply provided &#8220;/&#8221; as the request <abbr>URI</abbr> to match. Now when an offline user requests a resource that matches &#8220;/&#8221;, he will be served &#8220;offline.html&#8221; in its place. So if the user clicked on a link for &#8220;/status.html&#8221;, &#8220;/about.html&#8221;, or even &#8220;/my/nested/resource.html&#8221;, the browser would match the &#8220;/&#8221; at the start and serve up &#8220;offline.html&#8221;. Since I&#8217;ve used the root path, every uncached resource under this domain will point to &#8220;offline.html&#8221;.</p>
  
    <p class="disclaimer"><strong>Errata 23 June 2011:</strong> this article has been corrected as you <em>can&#8217;t</em> use a wildcard with the <code>FALLBACK</code> or <code>NETWORK</code> namespaces &#8211; though you can use the asterisk symbol under <code>NETWORK</code> as it&#8217;s a special flag to indicate all urls should be whitelisted.</p>

    <p>The <code>CACHE</code> section, both the <code>FALLBACK</code> and <code>NETWORK</code> namespaces support a prefix rule that aid their <abbr>URI</abbr> matching. In that any requests to the <code>/avatar</code> directory, whilst offline, if the asset is unavailable the browser can serve up an alternative.</p>
    
    <figure>
      <pre><code>CACHE MANIFEST

FALLBACK:
/images/avatars/ /offline_avatar.png</code></pre>
      <figcaption>A smarter fallback declaration</figcaption>
    </figure>
  
    <p>The first line tells the browser to serve &#8220;/offline_avatar.png&#8221; in place of user-uploaded avatars.</p>
  
    <p>Remember when I said that any document referencing the manifest will also be cached? Well, you can use this to your advantage! You can cache each page the user visits while online so that they will have access to that page while offline. Then anything they didn&#8217;t view will be caught by the <code>FALLBACK</code> section. This keeps you from explicitly stating you want all your pages cached, and, more importantly, avoids the huge performance penalty of serving all the resources you want cached every time someone first visits your site.</p>
  </section>
  
  <section id="network">
    <h3>NETWORK</h3>
    <p>Finally, we have the <code>NETWORK</code> section, used to tell the browser explicitly which resources are only available while online. By default, this uses the asterisk <code>*</code> symbol, meaning all resources that are not cached will require a connection. Alternatively we can whitelist specific url prefixes, like all the avatars if we wish.</p>
  
    <figure>
      <pre><code>CACHE MANIFEST

NETWORK:
*</code></pre>
      <figcaption>Adding a <code>NETWORK</code> section</figcaption>
    </figure>
  
    <p>You can explicitly define resources not to cache by providing a list of <abbr>URI</abbr>s — essentially a whitelist of online-only assets.</p>
  
    <figure>
      <pre><code>CACHE MANIFEST

NETWORK:
register.php
login.php</code></pre>
      <figcaption>Excluding certain pages from caching</figcaption>
    </figure>
  </section>

</section>

<section id="serving-manifest">
  <h2>Serving the manifest</h2>
  
  <p>You can reference a manifest file on a web page by adding the <code>manifest</code> attribute to your opening <code>&lt;html&gt;</code> tag. The browser will only cache pages that include this attribute (in addition to those specified in the manifest itself, though in that instance, the user would have to visit a page including the manifest in order for the browser to be aware of it).</p>
  
  <figure>
    <pre><code>&lt;!DOCTYPE html&gt;
&lt;html lang="en" manifest="/offline.appcache"&gt;
  // your html document
&lt;/html&gt;
</code></pre>
    <figcaption>Referencing the manifest file from an <abbr>HTML</abbr> page</figcaption>
  </figure>

  <p>The linked file should also be served with a <abbr>MIME</abbr>-type of <code>text/cache-manifest</code>. If you&#8217;re using <a href="http://httpd.apache.org/">Apache</a> as your web server, add this to your <code>.htaccess</code> file:</p>
  
  <figure>
    <pre><code>AddType text/cache-manifest .appcache
</code></pre>
  </figure>
  
  <p>And there you have it! Supporting browsers will retrieve the manifest file and cache each item on the list for offline use. Won&#8217;t your parents be proud?</p>
</section>

<section id="trigger-refresh">
  <h2>Triggering a cache refresh</h2>
  
  <p>Once a cache has been successfully downloaded, the browser will retain those assets until either the user clears the cache or you trigger an update. Triggering an update with your manifest file requires that the contents of that file change, not just the assets themselves.</p>
  
  <p><strong>Updating the assets on your server will not trigger a cache update. You must modify the manifest file.</strong></p>
  
  <p>If you&#8217;re adding or removing resources completely, you&#8217;ll have to edit your manifest file anyway. But what if you&#8217;re just amending an already cached stylesheet?</p>
  
  <p>This is where comments come in handy. Just throw in a simple version number comment that you change when you want to trigger an update:</p>
  
  <figure>
    <pre><code>CACHE MANIFEST
      
# Version 9

CACHE:
/css/screen.css</code></pre>
    <figcaption>A version comment in a manifest file</figcaption>
  </figure>

  <p>The next time you want to trigger a cache refresh, just increment the version number. When the user next visits the online version of a page including this manifest, it will re-download the manifest file, notice the change, download the listed assets, and purge the existing cache.</p>
  
  <p><strong>Browser bug:</strong> Firefox caches the manifest file itself and will not update it even if the manifest has changed on the server. With some server config wizardry, you can tell browsers that the cache of the manifest file is instantly invalidated and should be requested from the server every time it&#8217;s referenced. Add this to your <code>.htaccess</code> to put Firefox in its place:</p>
  
  <figure>
    <pre><code>&lt;IfModule mod_expires.c&gt;
  ExpiresActive On
  ExpiresByType text/cache-manifest "access plus 0 seconds"
&lt;/IfModule&gt;
</code></pre>
  </figure>
</section>

<section id="conclusion">
  <h2>Conclusion</h2>
  
  <p>The application cache is a powerful beast, and to tame it you need to be clear on what&#8217;s involved. Give thought to your <code>CACHE</code>, <code>FALLBACK</code>, and <code>NETWORK</code> sections to provide a suitable offline experience to your users.</p>
  
  <p>In a future article, we&#8217;ll show you how to use the <code>applicationCache</code> JavaScript object to manipulate the cache. Until then, this should be enough to get you started on the path to offline web content.</p>
  
  <p>You can see a live demo using the application cache over on Doctor Remy&#8217;s <a href="http://html5demos.com/offlineapp">HTML5 Demos</a>. Happy caching!</p>
</section>
<div id="crp_related"><h3>Related Posts:</h3><ul class="related"><li><a href="http://html5doctor.com/your-questions-answered-9/" rel="bookmark" class="crp_title">Your Questions Answered 9</a></li><li><a href="http://html5doctor.com/your-questions-answered-10/" rel="bookmark" class="crp_title">Your Questions Answered #10</a></li><li><a href="http://html5doctor.com/the-nsfw-element/" rel="bookmark" class="crp_title">The nsfw element</a></li><li><a href="http://html5doctor.com/server-sent-events/" rel="bookmark" class="crp_title">Server-Sent Events</a></li><li><a href="http://html5doctor.com/your-questions-answered-3/" rel="bookmark" class="crp_title">Your Questions Answered #3</a></li></ul></div><p><a href="http://html5doctor.com/go-offline-with-application-cache/" rel="bookmark">Go offline with application cache</a> originally appeared on <a href="http://html5doctor.com">HTML5 Doctor</a> on January 25, 2011.</p>
]]></content:encoded>
			<wfw:commentRss>http://html5doctor.com/go-offline-with-application-cache/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>You can still use div</title>
		<link>http://html5doctor.com/you-can-still-use-div/</link>
		<comments>http://html5doctor.com/you-can-still-use-div/#comments</comments>
		<pubDate>Tue, 13 Jul 2010 13:30:37 +0000</pubDate>
		<dc:creator>Mike Robinson</dc:creator>
				<category><![CDATA[Elements]]></category>
		<category><![CDATA[div]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[semantics]]></category>

		<guid isPermaLink="false">http://html5doctor.com/?p=1853</guid>
		<description><![CDATA[&#8220;Sorry, can you say that again?&#8221;, I hear you ask. Certainly: you can still use &#60;div&#62;! Despite HTML5 bringing us new elements like &#60;article&#62;, &#60;section&#62;, and &#60;aside&#62;, the &#60;div&#62; element still has its place. Let the HTML5 Doctor tell you why. Status: Unchanged In HTML 4, the &#60;div&#62; element was defined to be a generic [...]]]></description>
			<content:encoded><![CDATA[<p>&#8220;Sorry, can you say that again?&#8221;, I hear you ask. Certainly: you can still use <code>&lt;div&gt;</code>! Despite <abbr title="HyperText Markup Language">HTML</abbr>5 bringing us new elements like <code>&lt;article&gt;</code>, <code>&lt;section&gt;</code>, and <code>&lt;aside&gt;</code>, the <code>&lt;div&gt;</code> element still has its place. Let the <abbr>HTML</abbr>5 Doctor tell you why.</p>
<p><span id="more-1853"></span></p>
<h2>Status: Unchanged</h2>
<p>In <abbr>HTML</abbr> 4, the <code>&lt;div&gt;</code> element was defined to be a generic element for structuring a page. Although you can allude to the nature of its content by assigning <code>id</code> and <code>class</code> attributes with meaningful names, a <code>&lt;div&gt;</code> has almost no semantic meaning. <a href="http://dev.w3.org/html5/spec/Overview.html#the-div-element">The <abbr>HTML</abbr>5 definition</a>is basically the same as in <abbr>HTML</abbr> 4:</p>
<blockquote>
<p>The div element has no special meaning at all. It represents its children. It can be used with the class, lang, and title attributes to mark up semantics common to a group of consecutive elements.</p>
<footer>
    <cite><a href="http://dev.w3.org/html5/spec/Overview.html#the-div-element">W3C Specification</a></cite><br />
  </footer>
</blockquote>
<p><code>&lt;div&gt;</code> is literally a container for flow content*, a collection of (hopefully) more semantically marked-up content that may need to be grouped together. It lies at the opposite end of the semantic spectrum from the new <abbr>HTML</abbr>5 structural elements.</p>
<p><small>* For those who haven&#8217;t encountered this term before, <a href="http://dev.w3.org/html5/spec/Overview.html#flow-content-0">flow content</a> elements are the same as <abbr>HTML</abbr> 4&#8242;s block-level content elements.</small></p>
<h2><code>&lt;div&gt;</code> vs semantic elements</h2>
<p>The new semantic elements (<code>&lt;article&gt;</code>, <code>&lt;section&gt;</code>, and friends) justifiably capture a lot of <code>&lt;div&gt;</code>&#8216;s territory, but <code>&lt;div&gt;</code> still has a place in the <abbr>HTML</abbr>5 world. You should use <code>&lt;div&gt;</code> when there is no other more semantically appropriate element that suits your purpose. Its most common use will likely be for stylistic purposes — i.e., wrapping some semantically marked-up content in a <abbr>CSS</abbr>-styled container.</p>
<p>Ask yourself questions about your content: Is it part of the site&#8217;s navigation? Is the content secondary to its surrounding content? If this content were printed on a page with nothing else, would it make sense? You will need to evaluate your content carefully, thinking about what it is and pairing it with an appropriate element. I recommend taking a look at <a href="http://html5doctor.com/happy-1st-birthday-us/">The Amazing <abbr>HTML</abbr>5 Doctor Easily Confused <abbr>HTML</abbr>5 Element Flowchart of Enlightenment</a> to help you choose the right element for your flow content.</p>
<h2>Example Uses</h2>
<p>Below are a few examples of how you can still use <code>&lt;div&gt;</code> appropriately in your <abbr>HTML</abbr>5 sites.</p>
<h3>Site Wrapper</h3>
<p>While you can <a href="http://camendesign.com/code/developpeurs_sans_frontieres">use the <code>&lt;body&gt; element</code></a> as a &#8220;natural&#8221; wrapper for site content, many people like to use <code>&lt;div&gt;</code> as top-level container for styling the entire site. This is an appropriate use of <code>&lt;div&gt;</code>, as a site wrapper has no meaning or purpose other than to aid styling.</p>
<pre><code>&lt;body&gt;
  &lt;div id="wrapper"&gt;
    &lt;header&gt;
      &lt;h1&gt;My Happy Blog&lt;/h1&gt;
      &lt;nav&gt;
        &lt;!-- ... --&gt;
      &lt;/nav&gt;
    &lt;/header&gt;

    &lt;!-- ... rest of site content ... --&gt;
  &lt;/div&gt;
&lt;/body&gt;</code></pre>
<h3>Intro paragraph</h3>
<p>If you want to style a particular block of content, like the intro to an article, <code>&lt;div&gt;</code> is a perfectly suitable element:</p>
<pre><code>&lt;article&gt;
  &lt;h1&gt;Big announcement&lt;/h1&gt;
  &lt;div class="intro"&gt;
    &lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.&lt;/p&gt;
    &lt;p&gt;Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.&lt;/p&gt;
  &lt;/div&gt;
  &lt;p&gt;Sed massa metus, molestie nec facilisis non, lobortis ac orci. Suspendisse porttitor laoreet mi, at laoreet dolor rhoncus non. Sed ut massa quis mi placerat iaculis non sit amet odio. Cras tempus urna vitae felis rutrum porta.&lt;/p&gt;
  &lt;p&gt;Maecenas auctor lacus eget mauris tincidunt consectetur. Donec molestie malesuada ligula, sed feugiat massa consequat sit amet. Pellentesque orci metus, ultricies sit amet adipiscing eget, gravida fringilla dui. Vestibulum accumsan dui diam, eget venenatis urna. Sed eu lobortis justo. Aliquam erat volutpat. Aliquam erat volutpat.&lt;/p&gt;
&lt;/article&gt;</code></pre>
<p>The first two paragraphs aren&#8217;t really that different from the rest of the article, but by wrapping them in a <code>&lt;div&gt;</code>, they can be styled to capture the reader&#8217;s attention and draw them into the article. Of course, if you only want to style the first paragraph, you could use a <abbr>CSS</abbr> selector like <code>h1 + p {}</code> or <code>article p:first-child {}</code>. But if you want to style an article&#8217;s first paragraph only <em>sometimes</em>, or you need the style to work in older versions of Internet Explorer, or (as in this case) you want style more than one paragraph, a wrapper <code>&lt;div&gt;</code> is the way to go.</p>
<h3>Other uses for <code>&lt;div&gt;</code></h3>
<p>As previously stated, use of <code>&lt;div&gt;</code> will decline in favour of the new semantic elements. If you&#8217;re using lots of <code>&lt;div&gt;</code>s and only a few of the semantic elements in your <abbr>HTML</abbr>5 sites, then you&#8217;re really not taking advantage of what <abbr>HTML</abbr>5 has to offer.</p>
<p>That said, you may need to rely on <code>&lt;div&gt;</code> as you transition into the world of <abbr>HTML</abbr>5. For example, if many of your site&#8217;s visitors use Internet Explorer with JavaScript disabled, then you won&#8217;t be able to style the new elements for these users. A piece of advice we gave back in our article on <a href="http://html5doctor.com/how-to-use-html5-in-your-client-work-right-now/">how to use <abbr>HTML</abbr>5 in your client work right now</a> was to use <code>&lt;div&gt;</code> with classes named after the new semantic elements, getting you to think about how you would use the new semantic elements without actually using them.</p>
<pre><code>&lt;div class="article"&gt;
  &lt;div class="header"&gt;
    &lt;h1&gt;My blog post&lt;/h1&gt;
    &lt;p&gt;An example using divs with classes instead of the new elements.&lt;/p&gt;
  &lt;/div&gt;
  &lt;!-- ... content ... --&gt;
&lt;/div&gt;

&lt;article&gt;
  &lt;header&gt;
    &lt;h1&gt;My blog post&lt;/h1&gt;
    &lt;p&gt;The same article but switched to the new elements.&lt;/p&gt;
  &lt;/header&gt;
  &lt;!-- ... content ... --&gt;
&lt;/article&gt;</code></pre>
<p>This makes it simple to switch to the new elements when it becomes practical (think &#8220;search and replace&#8221;).</p>
<h2>Recap</h2>
<p>You will certainly use <code>&lt;div&gt;</code> less often in <abbr>HTML</abbr>5 than you did in <abbr>HTML</abbr> 4, but it&#8217;s still a valuable element to have in your toolkit. Sure, it&#8217;ll be picked last for the team because everyone else is better, but it&#8217;ll be the best damn generic container element there is!*</p>
<p>Look at the more semantically valuable elements and consider whether your content would benefit from what they offer. Need help deciding? Take a look at some of these articles right here on <abbr>HTML</abbr>5 Doctor:</p>
<ul>
<li><a href="http://html5doctor.com/the-header-element/">header</a></li>
<li><a href="http://html5doctor.com/the-footer-element/">footer</a></li>
<li><a href="http://html5doctor.com/aside-revisited/">aside</a></li>
<li><a href="http://html5doctor.com/the-article-element/">article</a></li>
<li><a href="http://html5doctor.com/the-section-element/">section</a></li>
<li><a href="http://html5doctor.com/the-figure-figcaption-elements/">figure</a></li>
<li><a href="http://html5doctor.com/nav-element/">nav</a></li>
</ul>
<p>For more, check our <a href="http://html5doctor.com/article-archive/">article archive</a>. And if all else fails, use a <code>&lt;div&gt;</code>!</p>
<p><small>* As it should be, it&#8217;s the only one apart from <code>&lt;span&gt;</code>. That said, if your content is just text, perhaps the oft-overlooked <code>&lt;p&gt;</code> would be more appropriate.</small>
<div id="crp_related">
<h3>Related Posts:</h3>
<ul class="related">
<li><a href="http://html5doctor.com/understanding-aside/" rel="bookmark" class="crp_title">Understanding aside</a></li>
<li><a href="http://html5doctor.com/aside-revisited/" rel="bookmark" class="crp_title">Aside Revisited</a></li>
<li><a href="http://html5doctor.com/the-details-and-summary-elements/" rel="bookmark" class="crp_title">The details and summary elements</a></li>
<li><a href="http://html5doctor.com/the-header-element/" rel="bookmark" class="crp_title">The header element</a></li>
<li><a href="http://html5doctor.com/the-hgroup-element/" rel="bookmark" class="crp_title">The hgroup element</a></li>
</ul>
</div>
<p><a href="http://html5doctor.com/you-can-still-use-div/" rel="bookmark">You can still use div</a> originally appeared on <a href="http://html5doctor.com">HTML5 Doctor</a> on July 13, 2010.</p>
]]></content:encoded>
			<wfw:commentRss>http://html5doctor.com/you-can-still-use-div/feed/</wfw:commentRss>
		<slash:comments>39</slash:comments>
		</item>
		<item>
		<title>The dl element</title>
		<link>http://html5doctor.com/the-dl-element/</link>
		<comments>http://html5doctor.com/the-dl-element/#comments</comments>
		<pubDate>Thu, 03 Jun 2010 14:00:10 +0000</pubDate>
		<dc:creator>Mike Robinson</dc:creator>
				<category><![CDATA[Elements]]></category>
		<category><![CDATA[dd]]></category>
		<category><![CDATA[dl]]></category>
		<category><![CDATA[dt]]></category>
		<category><![CDATA[HTML 5]]></category>
		<category><![CDATA[html5]]></category>

		<guid isPermaLink="false">http://html5doctor.com/?p=725</guid>
		<description><![CDATA[The &#60;dl&#62; element existed in HTML 4, but it&#8217;s been repurposed in HTML5. Let the Doctor explain what&#8217;s changed and how it can be used. It’s all in the description In HTML 4, &#60;dl&#62; was considered a “definition list”, containing groups of terms and their definitions. The terms and definitions were a many-to-many relationship: one [...]]]></description>
			<content:encoded><![CDATA[<p>The <code>&lt;dl&gt;</code> element existed in <abbr title="Hypertext Mark-up Language">HTML</abbr> 4, but it&#8217;s been repurposed in <abbr>HTML</abbr>5. Let the Doctor explain what&#8217;s changed and how it can be used.</p>
<p><span id="more-725"></span></p>
<h2>It’s all in the description</h2>
<p>In <abbr>HTML</abbr> 4, <code>&lt;dl&gt;</code> was considered a “definition list”, containing groups of terms and their definitions. The terms and definitions were a many-to-many relationship: one or more terms to one or more definitions. The element was often misunderstood and therefore misused or not used at all in favour of more widely used and (perhaps) less semantic markup.</p>
<p>To address these issues, <code>&lt;dl&gt;</code>’s definition has been refined in <abbr>HTML</abbr>5 as a <a href="http://www.w3.org/TR/html-markup/dl.html#dl">description list</a>. From the spec:</p>
<blockquote><p>The dl element represents an association list consisting of zero or more name-value groups (a description list). Each group must consist of one or more names (dt elements) followed by one or more values (dd elements). Within a single dl element, there should not be more than one dt element for each name.</p>
</blockquote>
<p>It maintains the many-to-many relationship between names and values. These groupings use <a href="http://www.w3.org/TR/html-markup/dt.html#dt"><code>&lt;dt&gt;</code></a> to represent the term or name and <a href="http://www.w3.org/TR/html-markup/dd.html#dd"><code>&lt;dd&gt;</code></a> for the description. Also note the last line of the quote, stating that a name should not be used more than once within a single <code>&lt;dl&gt;</code>.</p>
<h2>Example Uses</h2>
<p>I&#8217;ve put together a couple of appropriate uses of <code>&lt;dl&gt;</code> to get your creative juices flowing.</p>
<h3>Glossary</h3>
<p><code>&lt;dl&gt;</code> can be used to mark-up a glossary of terms, although you must remember to use <code>&lt;dfn&gt;</code> to indicate that the word is defined here:</p>
<pre><code>&lt;article&gt;
  &lt;h1&gt;The article element&lt;/h1&gt;
  &lt;p&gt;An independent piece of content, one suitable for putting in an
    article element, is content that makes sense on it&rsquo;s own. This yardstick
    is up to your interpretation, but an easy smell test is would this make sense
    in an RSS feed? Of course weblog articles and static pages would make sense
    in a feed reader, and some sites have weblog comment feeds..&lt;/p&gt;
  ...
  &lt;aside&gt;
    &lt;h2&gt;Glossary&lt;/h2&gt;
    &lt;dl&gt;
      &lt;dt&gt;&lt;dfn&gt;RSS&lt;/dfn&gt;&lt;/dt&gt;
      &lt;dd&gt;An XML format for aggregating information from websites whose
        content is frequently updated.&lt;/dd&gt;
      &lt;dt&gt;&lt;dfn&gt;Weblog&lt;/dfn&gt;&lt;/dt&gt;
      &lt;dd&gt;Contraction of the term &quot;web log&quot;, a weblog is a
        website that is periodically updated, like a journal&lt;/dd&gt;
    &lt;/dl&gt;
  &lt;/aside&gt;
&lt;/aticle&gt;
</code></pre>
<p>The example content is from <a href="http://html5doctor.com/the-article-element/">our recent post on the article element</a>. In the example, I plucked out the terms &#8220;RSS&#8221; and &#8220;weblog&#8221; and defined them in a handy glossary. Since this information is supplementary to the article, the glossary has been placed in an <code>&lt;aside&gt;</code>.</p>
<h3>Metadata</h3>
<p><code>&lt;dl&gt;</code> is also appropriate for marking up content metadata, such as information about our article on <a href="http://html5doctor.com/how-to-use-html5-in-your-client-work-right-now/">how to use <abbr>HTML</abbr>5 in your client work right now</a>.</p>
<pre><code>&lt;dl&gt;
  &lt;dt&gt;Authors:&lt;/dt&gt;
  &lt;dd&gt;Remy Sharp&lt;/dd&gt;
  &lt;dd&gt;Rich Clark&lt;/dd&gt;
  &lt;dt&gt;Editor:&lt;/dt&gt;
  &lt;dd&gt;Brandan Lennox&lt;/dd&gt;
  &lt;dt&gt;Category:&lt;/dt&gt;
  &lt;dd&gt;Comment&lt;/dd&gt;
&lt;/dl&gt;
</code></pre>
<p>Since Remy and Richard contributed to that article, they are both listed as authors, showing the pairing of multiple values (<code>&lt;dd&gt;</code>) to one key (<code>&lt;dt&gt;</code>).</p>
<h3>Multiple keys (<code>&lt;dt&gt;</code>) to a single value</h3>
<p>As mentioned above, a <code>&lt;dl&gt;</code> may map many keys (<code>&lt;dt&gt;</code>) to many values (<code>&lt;dd&gt;</code>). This means that one term might have multiple descriptions, or there may be multiple terms that mean the same thing. Related <code>&lt;dt&gt;</code>s should follow each other immediately before their descriptive <code>&lt;dd&gt;</code>.</p>
<pre><code>&lt;dl&gt;
  &lt;dt lang="en-GB"&gt;&lt;dfn&gt;colour&lt;/dfn&gt;&lt;/dt&gt;
  &lt;dt lang="en-US"&gt;&lt;dfn&gt;color&lt;/dfn&gt;&lt;/dt&gt;
  &lt;dd&gt;The visual result of light in their emission, transmission and/or reflection. This perception is determined by the hue, brightness and saturation of the light at a specific point. &lt;/dd&gt;
&lt;/dl&gt;
</code></pre>
<p>Here I have indicated that there are two different spellings of &#8220;colour&#8221; and grouped these terms to match them with the same description.</p>
<p>It is not appropriate, however, to use the same key multiple times within a single <code>&lt;dl&gt;</code>. You can&#8217;t define &#8220;car&#8221; as one thing at the start of a <code>&lt;dl&gt;</code> and then define it again at the end of that same <code>&lt;dl&gt;</code>. If you have multiple descriptions for a single term, you should list both <code>&lt;dd&gt;</code>s directly under the same <code>&lt;dt&gt;</code>.</p>
<pre><code>&lt;dl&gt;
  &lt;dt&gt;&lt;dfn&gt;Chips&lt;/dfn&gt;&lt;/dt&gt;
  &lt;dd&gt;Strips of potato usually deep fried in fat. Commonly referred to as "french fries".&lt;/dd&gt;
  &lt;dd&gt;A small fragment that has been broken off from a larger body (e.g. stone).&lt;/dd&gt;
&lt;/dl&gt;
</code></pre>
<h2>What it should not be used for</h2>
<p>Dialogue was a suggested use for <code>&lt;dl&gt;</code> in <abbr>HTML</abbr> 4, which was widely debated and often considered inappropriate. This application of the element is no longer recommended in <abbr>HTML</abbr>5, and the new definition of the element does indeed back this up. When marking up a conversation, you&#8217;re not describing the speaker, but rather stating what they said. With the demise of <a href="http://html5doctor.com/a-little-more-conversation-with-dialog/"><code>&lt;dialog&gt;</code></a>, conversations have no specific markup element. Instead, the specification makes recommendations of <a href="http://dev.w3.org/html5/spec/Overview.html#conversations">how to mark up conversations</a>.</p>
<h2>Summary</h2>
<p>The changes to <code>&lt;dl&gt;</code> are fairly minor, but the new definition should clear up confusion and enable developers to use it more appropriately. You can use this element to represent key-value pairs semantically and couple it with other elements like <code>&lt;details&gt;</code> and <code>&lt;aside&gt;</code> to give context to this information.</p>
<p>Where do you see yourself using <code>&lt;dl&gt;</code> in <abbr>HTML</abbr>5? Perhaps details about a downloadable file? Or are you going to give your more technical blog articles a glossary? Let us know in the comments!</p>
<div id="crp_related">
<h3>Related Posts:</h3>
<ul class="related">
<li><a href="http://html5doctor.com/the-article-element/" rel="bookmark" class="crp_title">The article element</a></li>
<li><a href="http://html5doctor.com/a-little-more-conversation-with-dialog/" rel="bookmark" class="crp_title">A little more conversation with dialog</a></li>
<li><a href="http://html5doctor.com/html5-doctor-glossary/" rel="bookmark" class="crp_title">HTML5 Doctor Glossary</a></li>
<li><a href="http://html5doctor.com/aside-revisited/" rel="bookmark" class="crp_title">Aside Revisited</a></li>
<li><a href="http://html5doctor.com/your-questions-18/" rel="bookmark" class="crp_title">Your Questions 18</a></li>
</ul>
</div>
<p><a href="http://html5doctor.com/the-dl-element/" rel="bookmark">The dl element</a> originally appeared on <a href="http://html5doctor.com">HTML5 Doctor</a> on June 3, 2010.</p>
]]></content:encoded>
			<wfw:commentRss>http://html5doctor.com/the-dl-element/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
		<item>
		<title>HTML5 Doctor Speaking and Training Appearances</title>
		<link>http://html5doctor.com/speaking/</link>
		<comments>http://html5doctor.com/speaking/#comments</comments>
		<pubDate>Fri, 16 Apr 2010 13:30:40 +0000</pubDate>
		<dc:creator>Mike Robinson</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[talks]]></category>
		<category><![CDATA[training]]></category>
		<category><![CDATA[workshops]]></category>

		<guid isPermaLink="false">http://html5doctor.com/?p=1577</guid>
		<description><![CDATA[<p>Even after slaving away at the web's operating table, the <abbr>HTML</abbr>5 Doctors still find time to speak about <abbr>HTML</abbr>5 at industry events. We'd like to make sure you don't miss out on future chances to see the doctors in action.</p>]]></description>
			<content:encoded><![CDATA[<p>Even after slaving away at the web&#8217;s operating table, the <abbr>HTML</abbr>5 Doctors still find time to speak about <abbr>HTML</abbr>5 at industry events. We&#8217;d like to make sure you don&#8217;t miss out on future chances to see the doctors in action.</p>

<p>For your convenience, we&#8217;ve put together a list of events where we&#8217;ll be speaking and even the ones we&#8217;re simply attending. Read on for some of our upcoming <abbr>HTML</abbr>5 appearances.</p>

<p>We&#8217;ll continue to maintain this page with new listings, so check back often. Otherwise you might miss us!</p>

<section class="vcalendar">
  <h2>Upcoming Talks</h2>
  <p>Here are some of the <abbr>HTML</abbr>5 talks we will be giving at various events. Make sure you mark them down in your calendars!</p>
</section>

<section class="vcalendar">  
  <h2>In Attendance</h2>
  <p>Of course, we aren&#8217;t always talking. We still attend events to listen to talks ourselves. If you see us there, come and say hi.</p>
<article class="vevent"> 
  <h3 class="summary"> 
    <a href="http://atnd.org/events/5181" class="url">Designing for iPad; our experiences so far</a> 
  </h3> 
  <details open="open"> 
    <abbr class="dtstart" title="2010-07-21T19:00:00">21 Jul</abbr> &#8211; 
    <em class="attendee">Oli Studholme</em> &#8211; 
    <span class="location">Apple Ginza</span> 
  </details> 
</article>

<article class="vevent"> 
  <h3 class="summary"> 
    <a href="http://buildconf.com/" class="url">Build</a> 
  </h3> 
  <details open="open"> 
    <abbr class="dtstart" title="2010-11-10T09:00:00">10 Nov</abbr> &#8211; 
    <em class="attendee">Jack Osborne</em> &#8211; 
    <span class="location">Waterfront Studio, Belfast</span> 
  </details> 
</article>
</section>

<h2>Run an event? Get in touch!</h2>
<p>If you organise an event or workshop and would like us to speak (or you&#8217;d just like to see us there), then we&#8217;d love to <a href="http://html5doctor.com/contact/">hear from you</a>.</p><div id="crp_related"><h3>Related Posts:</h3><ul class="related"><li><a href="http://html5doctor.com/web-directions-atmedia-2010/" rel="bookmark" class="crp_title">HTML5 Doctor at Web Directions @media</a></li><li><a href="http://html5doctor.com/microformats/" rel="bookmark" class="crp_title">Extending HTML5 — Microformats</a></li><li><a href="http://html5doctor.com/microdata/" rel="bookmark" class="crp_title">Extending HTML5 — Microdata</a></li><li><a href="http://html5doctor.com/storing-data-the-simple-html5-way-and-a-few-tricks-you-might-not-have-known/" rel="bookmark" class="crp_title">Storing Data the Simple HTML5 Way (and a few tricks you might not have known)</a></li><li><a href="http://html5doctor.com/summary-figcaption-element/" rel="bookmark" class="crp_title">Hello, summary and figcaption elements</a></li></ul></div><p><a href="http://html5doctor.com/speaking/" rel="bookmark">HTML5 Doctor Speaking and Training Appearances</a> originally appeared on <a href="http://html5doctor.com">HTML5 Doctor</a> on April 16, 2010.</p>
]]></content:encoded>
			<wfw:commentRss>http://html5doctor.com/speaking/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Aside Revisited</title>
		<link>http://html5doctor.com/aside-revisited/</link>
		<comments>http://html5doctor.com/aside-revisited/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 14:23:57 +0000</pubDate>
		<dc:creator>Mike Robinson</dc:creator>
				<category><![CDATA[Elements]]></category>
		<category><![CDATA[article]]></category>
		<category><![CDATA[aside]]></category>
		<category><![CDATA[HTML 5]]></category>
		<category><![CDATA[html5]]></category>

		<guid isPermaLink="false">http://html5doctor.com/?p=1015</guid>
		<description><![CDATA[Since the <abbr>HTML</abbr>5 specification is not yet final, we can expect changes to improve on the good bits and cut out the bad bits. <code>aside</code> &#8212; a misunderstood good bit &#8212; has now been tweaked based on feedback from the web development community. In this article, we'll take a look at what's changed.]]></description>
			<content:encoded><![CDATA[<p>Since the <abbr>HTML</abbr>5 specification is not yet final, we can expect changes to improve on the good bits and cut out the bad bits. <code>aside</code> &#8212; a misunderstood good bit &#8212; has now been tweaked based on feedback from the web development community. In this article, we&#8217;ll take a look at what&#8217;s changed.</p>
<h2>Aside redefined</h2>
<p>When we previously discussed <code>aside</code> in &#8220;<a href="/understanding-aside/">Understanding Aside</a>&#8220;, its definition suggested that it should be used for content tangentially related to the content surrounding it, such as related reading links and glossaries. It did <em>not</em> appear to be an appropriate element for holding secondary content related to the site as a whole, typically known as a &#8220;sidebar&#8221;.</p>
<p>From the comments here and elsewhere, you can see this definition was not accepted by developers. The spec writers listened, and <code>aside</code> is now acceptable for secondary content when not nested within an <code>article</code> element.</p>
<h2>Examples of <code>aside</code> in two different contexts</h2>
<p>With the new definition of <code>aside</code>, it&#8217;s crucial to remain aware of its context. When used <em>within</em> an <code>article</code> element, the contents should be specifically related to that article (e.g., a glossary). When used <em>outside</em> of an <code>article</code> element, the contents should be related to the site (e.g., a blogroll, groups of additional <a href="/nav-element/">navigation</a>, and even advertising if that content is related to the page).</p>
<p>The two uses of <code>aside</code> can be best illustrated with an example:</p>
<pre><code>&lt;body&gt;
  &lt;header&gt;
    &lt;h1&gt;My Blog&lt;/h1&gt;
  &lt;/header&gt;
  &lt;article&gt;
    &lt;h1&gt;My Blog Post&lt;/h1&gt;
    &lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
    eiusmod tempor incididunt ut labore et dolore magna aliqua.&lt;/p&gt;
    &lt;aside&gt;
      &lt;!-- Since this aside is contained within an article, a parser
      should understand that the content of this aside is directly related
      to the article itself. --&gt;
      &lt;h1&gt;Glossary&lt;/h1&gt;
      &lt;dl&gt;
        &lt;dt&gt;Lorem&lt;/dt&gt;
        &lt;dd&gt;ipsum dolor sit amet&lt;/dd&gt;
      &lt;/dl&gt;
    &lt;/aside&gt;
  &lt;/article&gt;
  &lt;aside&gt;
    &lt;!-- This aside is outside of the article. Its content is related
    to the page, but not as closely related to the above article --&gt;
    &lt;h2&gt;Blogroll&lt;/h2&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#&quot;&gt;My Friend&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#&quot;&gt;My Other Friend&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#&quot;&gt;My Best Friend&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/aside&gt;
&lt;/body&gt;
</code></pre>
<h2>Conclusion</h2>
<p>The <code>aside</code> element can now represent secondary content when used outside of an <code>article</code>. Keep in mind that <code>aside</code> &#8212; and, more generally, secondary content &#8212; does not <em>necessarily</em> mean &#8220;sidebar&#8221;. The style of the content should not dictate the use of the element. For content that is not the primary focus of an article (or page) but is still <em>related</em> to the article (or page), <code>aside</code> is what you need, regardless of its visual design.</p>
<div id="crp_related">
<h3>Related Posts:</h3>
<ul class="related">
<li><a href="http://html5doctor.com/understanding-aside/" rel="bookmark" class="crp_title">Understanding aside</a></li>
<li><a href="http://html5doctor.com/you-can-still-use-div/" rel="bookmark" class="crp_title">You can still use div</a></li>
<li><a href="http://html5doctor.com/designing-a-blog-with-html5/" rel="bookmark" class="crp_title">Designing a blog with html5</a></li>
<li><a href="http://html5doctor.com/the-hgroup-hokey-cokey/" rel="bookmark" class="crp_title">The hgroup hokey cokey</a></li>
<li><a href="http://html5doctor.com/the-dl-element/" rel="bookmark" class="crp_title">The dl element</a></li>
</ul>
</div>
<p><a href="http://html5doctor.com/aside-revisited/" rel="bookmark">Aside Revisited</a> originally appeared on <a href="http://html5doctor.com">HTML5 Doctor</a> on October 28, 2009.</p>
]]></content:encoded>
			<wfw:commentRss>http://html5doctor.com/aside-revisited/feed/</wfw:commentRss>
		<slash:comments>73</slash:comments>
		</item>
		<item>
		<title>Draw attention with mark</title>
		<link>http://html5doctor.com/draw-attention-with-mark/</link>
		<comments>http://html5doctor.com/draw-attention-with-mark/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 13:10:43 +0000</pubDate>
		<dc:creator>Mike Robinson</dc:creator>
				<category><![CDATA[Elements]]></category>
		<category><![CDATA[HTML 5]]></category>
		<category><![CDATA[mark]]></category>

		<guid isPermaLink="false">http://html5doctor.com/?p=771</guid>
		<description><![CDATA[Other than allowing Mark's everywhere to <em>rejoice</em> that they have an element that shares their name, HTML 5 introduces mark as a way to highlight text to indicate its relevance to the user. Read on as we tally up the uses of this new element.]]></description>
			<content:encoded><![CDATA[<p>Other than allowing Marks everywhere to <em>rejoice</em> that they have an element that shares their name, HTML 5 introduces <code>mark</code> as a way to highlight text to indicate its relevance to the user. Read on as we tally up the uses of this new element.<span id="more-771"></span></p>
<p>As always, the defining text passed down to us in the <a href="http://dev.w3.org/html5/spec/Overview.html#the-mark-element">specification</a>:</p>
<blockquote><p>The mark element represents a run of text in one document marked or highlighted for reference purposes, due to its relevance in another context. When used in a quotation or other block of text referred to from the prose, it indicates a highlight that was not originally present but which has been added to bring the reader&#8217;s attention to a part of the text that might not have been considered important by the original author when the block was originally written, but which is now under previously unexpected scrutiny. When used in the main prose of a document, it indicates a part of the document that has been highlighted due to its likely relevance to the user&#8217;s current activity.</p>
</blockquote>
<p>Both uses are aimed at drawing attention to what is relevant to the user. <code>mark</code> can provide a very useful aid to the user with appropriate styling.</p>
<h2>Examples</h2>
<h3>Search Results</h3>
<p>A prime example of how to use <code>mark</code> today is to highlight the term a user has searched for. Many search engines already do this using other methods to mark the text, which shows the need for this new element.</p>
<pre><code>&lt;h1&gt;716,000,000 search results for the query &quot;&lt;mark&gt;HTML 5&lt;/mark&gt;&quot;&lt;/h1&gt;
&lt;section id=&quot;search-results&quot;&gt;
  &lt;article&gt;
    &lt;h2&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/HTML_5&quot;&gt;&lt;mark&gt;HTML 5&lt;/mark&gt; - Wikipedia, the free encyclopedia&lt;/a&gt;&lt;/h2&gt;
    &lt;p&gt;&lt;mark&gt;HTML 5&lt;/mark&gt; is the next major revision of &lt;mark&gt;HTML&lt;/mark&gt; (&quot;hypertext markup language&quot;), the core markup language of the World Wide Web. The WHATWG started work on the ... &lt;a href=&quot;http://en.wikipedia.org/wiki/HTML_5&quot;&gt;Read more&lt;/a&gt;&lt;/p&gt;
  &lt;/article&gt;
  &lt;article&gt;
    &lt;h2&gt;&lt;a href=&quot;http://dev.w3.org/html5/spec/Overview.html&quot;&gt;&lt;mark&gt;HTML 5&lt;/mark&gt;&lt;/a&gt;&lt;/h2&gt;
    &lt;p&gt;A vocabulary and associated APIs for &lt;mark&gt;HTML&lt;/mark&gt; and XHTML. Editor's Draft 16 August 2009. Latest Published Version: http://www.w3.org/TR/&lt;mark&gt;html5&lt;/mark&gt;/; Latest Editor's ... &lt;a href=&quot;http://dev.w3.org/html5/spec/Overview.html&quot;&gt;Read more&lt;/a&gt;&lt;/p&gt;
  &lt;/article&gt;
  &lt;article&gt;
    &lt;h2&gt;&lt;a href=&quot;http://www.whatwg.org/specs/web-apps/current-work/multipage/&quot;&gt;&lt;mark&gt;HTML 5&lt;/mark&gt;&lt;/a&gt;&lt;/h2&gt;
    &lt;p&gt;Multiple-page version: http://whatwg.org/&lt;mark&gt;html5&lt;/mark&gt;; One-page version: http://www.whatwg.org/specs/web-apps/current-work/; PDF print versions: ... &lt;a href=&quot;http://www.whatwg.org/specs/web-apps/current-work/multipage/&quot;&gt;Read more&lt;/a&gt;&lt;/p&gt;
  &lt;/article&gt;
  &lt;article&gt;
    &lt;h2&gt;&lt;a href=&quot;http://html5gallery.com/&quot;&gt;&lt;mark&gt;HTML5&lt;/mark&gt; Gallery | A showcase of sites using &lt;mark&gt;HTML 5&lt;/mark&gt; markup&lt;/a&gt;&lt;/h2&gt;
    &lt;p&gt;A showcase of sites using &lt;mark&gt;html5&lt;/mark&gt; markup, with twin primary aims to help web designers and developers of how to implement &lt;mark&gt;html5&lt;/mark&gt; into their sites now, ... &lt;a href=&quot;http://html5gallery.com/&quot;&gt;Read more&lt;/a&gt;&lt;/p&gt;
  &lt;/article&gt;
&lt;/section&gt;
&lt;nav&gt;
  &lt;ol&gt;
    &lt;li&gt;1&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;2&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;3&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;4&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;5&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;...&lt;/li&gt;
  &lt;/ol&gt;
&lt;/nav&gt;
</code></pre>
<p><a href="http://jsbin.com/uleza">View a live example</a></p>
<p>Any instance of &#8220;HTML 5&#8243;, and even simply &#8220;HTML&#8221;, has been marked as relevant to the user&#8217;s search. This can help the user see how relevant their search results are, so they can pick the best results for what they need. When implementing this in a language like PHP, you can use functions like <a href="http://php.net/str_replace"><code>str_replace()</code></a> or some clever <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expressions</a> to find the search term within your output and wrap <code>mark</code> around each instance.</p>
<h3>Quotes</h3>
<p>In all the brilliant things that have been said, there is always a chance that someone will come back to scrutinize parts in the future. These pieces of text or speech may not have had any importance when they were original formed, and hence not been given such emphasis, but now have attracted particular interest by a another party. <code>mark</code> can be used in quotations to highlight such text.</p>
<pre><code>&lt;p&gt;Mike once said:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Google won't last, &lt;mark&gt;they will fail&lt;/mark&gt; at search and advertising as nothing will topple Yahoo.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Of course, we now know he was wrong. Google has not failed, they excelled in search and online advertising, making them a very profitable company.&lt;/p&gt;
</code></pre>
<p>Here I have quoted myself, highlighting where I was wrong in my original statement and then immediately correcting this error in the following paragraph.</p>
<h2>Differences from strong and em</h2>
<p>Previously, you may have used <code>em</code> and <code>strong</code> for adding emphasis or importance, respectively, to portions of text. <code>mark</code> differs from these two as it is used purely for highlighting the relevance of a piece of text to the user and/or page&#8217;s content. In the past you may have used <code>em</code> and <code>strong</code> for this purpose, which was arguably valid at the time due to the lack of a better element, but the introduction of <code>mark</code> simply means their use will be more strict.</p>
<p>Use <code>strong</code> when you need to indicate the importance of a piece of text, such as an error or warning message, and <code>em</code> should be for adding emphasis to text, stressing words to adapt the meaning of a sentence.</p>
<h2>Final Thoughts</h2>
<p>The addition of <code>mark</code> to HTML is welcome, preventing stretching the definitions of <code>strong</code> and <code>em</code> too thin. There are many practical uses of <code>mark</code> in the world today, particularly for search and educational articles like tutorials. Put your highlighter pens down and start using <code>mark</code> to highlight relevant text (it&#8217;s better for your screen!).</p>
<p><small><strong>Disclaimer</strong>: I have nothing against Google, this was merely a fictitious example vaguely related to the use of <code>mark</code> in search. Long live Google?</small>
<div id="crp_related">
<h3>Related Posts:</h3>
<ul class="related">
<li><a href="http://html5doctor.com/html5-simplequiz-5-urls-of-commenters/" rel="bookmark" class="crp_title">HTML5 Simplequiz 5: URLs of commenters</a></li>
<li><a href="http://html5doctor.com/block-level-links-in-html-5/" rel="bookmark" class="crp_title">&#8220;Block-level&#8221; links in HTML5</a></li>
<li><a href="http://html5doctor.com/html5-simplequiz-4-figures-captions-and-alt-text/" rel="bookmark" class="crp_title">HTML5 Simplequiz #4: figures, captions and alt text</a></li>
<li><a href="http://html5doctor.com/aside-revisited/" rel="bookmark" class="crp_title">Aside Revisited</a></li>
<li><a href="http://html5doctor.com/html-5-boilerplates/" rel="bookmark" class="crp_title">HTML5 Boilerplates</a></li>
</ul>
</div>
<p><a href="http://html5doctor.com/draw-attention-with-mark/" rel="bookmark">Draw attention with mark</a> originally appeared on <a href="http://html5doctor.com">HTML5 Doctor</a> on August 18, 2009.</p>
]]></content:encoded>
			<wfw:commentRss>http://html5doctor.com/draw-attention-with-mark/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>A little more conversation with dialog</title>
		<link>http://html5doctor.com/a-little-more-conversation-with-dialog/</link>
		<comments>http://html5doctor.com/a-little-more-conversation-with-dialog/#comments</comments>
		<pubDate>Wed, 12 Aug 2009 13:57:12 +0000</pubDate>
		<dc:creator>Mike Robinson</dc:creator>
				<category><![CDATA[Elements]]></category>
		<category><![CDATA[conversation]]></category>
		<category><![CDATA[dd]]></category>
		<category><![CDATA[dialog]]></category>
		<category><![CDATA[dt]]></category>
		<category><![CDATA[HTML 5]]></category>

		<guid isPermaLink="false">http://html5doctor.com/?p=707</guid>
		<description><![CDATA[Less action, more conversation. That's how that Elvis song went, right? OK, perhaps not. Regardless, the new dialog element introduced in HTML 5 is all about marking up the conversation, and it uses a couple of elements you may have already heard of. Sure, it's a little less action than something like audio, but it is still a useful element to semantically mark up many forms of dialogue.]]></description>
			<content:encoded><![CDATA[<p>Less action, more conversation. That&#8217;s how that <a href="http://en.wikipedia.org/wiki/A_Little_Less_Conversation">Elvis song</a> went, right? OK, perhaps not. Regardless, the new <code>dialog</code> element introduced in <abbr title="Hypertext Mark-up Language">HTML</abbr> 5 is all about marking up the conversation, and it uses a couple of elements you may have already heard of. Sure, it&#8217;s a little less action than something like <a href="http://html5doctor.com/native-audio-in-the-browser/"><code>audio</code></a>, but it is still a useful element to semantically mark up many forms of dialogue.<span id="more-707"></span></p>
<h2>Defining dialog</h2>
<p>The <a href="http://dev.w3.org/html5/spec/Overview.html">HTML 5 specification</a> defines <code>dialog</code> as follows:</p>
<blockquote><p>The dialog element represents a conversation, meeting minutes, a chat transcript, a dialog in a screenplay, an instant message log, or some other construct in which different players take turns in discourse.</p>
</blockquote>
<p>That&#8217;s a lot of different types of dialogue that can be marked up. A <code>dialog</code> element contains the <code>dt</code> element for a speaker&#8217;s name, and <code>dd</code> for what they said. That&#8217;s right, <code>dialog</code> borrows two elements from <code>dl</code> to pair up a speaker and what they say. The definition of a <code>dl</code> itself has changed in HTML 5 to become an association list, pairing names (<code>dt</code>) with values (<code>dd</code>). <code>dialog</code> uses this in a similar way, pairing a name of a speaker with whatever they said.</p>
<p>This means that the <code>dt</code> is the source (speaker) of what is within the following <code>dd</code>, and the <code>dd</code> contains a quotation from that source. Therefore, <code>dialog</code> does not require the use of <code>cite</code>, <code>blockquote</code> or <code>q</code>. The only time a <code>q</code> would be appropriate within <code>dialog</code> would be if what one person said contained a quotation from someone else. It is also possible to use <code>p</code> within a <code>dd</code>, should you need to mark-up large responses as paragraphs.</p>
<p>Also, despite the fact both <code>dialog</code> and <code>dl</code> share <code>dt</code> and <code>dd</code>, a dialogue should never be marked up with a <code>dl</code>. However, appropriate uses of <code>dl</code> is beyond the scope of this article and will be revisited in a separate article.</p>
<h2>Enough talk, let&#8217;s get practical</h2>
<h3>Marked Up Humour</h3>
<p>My first example is very straight forward. Using <code>dialog</code>, I will mark up a hilarious &#8220;Knock, Knock&#8221; joke.</p>
<pre><code>&lt;dialog&gt;
  &lt;dt&gt;Sam&lt;/dt&gt;
  &lt;dd&gt;Knock, Knock.&lt;/dd&gt;
  &lt;dt&gt;Eric&lt;/dt&gt;
  &lt;dd&gt;Who&apos;s there?&lt;/dd&gt;
  &lt;dt&gt;Sam&lt;/dt&gt;
  &lt;dd&gt;Justin.&lt;/dd&gt;
  &lt;dt&gt;Eric&lt;/dt&gt;
  &lt;dd&gt;Justin who?&lt;/dd&gt;
  &lt;dt&gt;Sam&lt;/dt&gt;
  &lt;dd&gt;Justin time for dinner!&lt;/dd&gt;
&lt;/dialog&gt;
</code></pre>
<p>Note that two people are in this conversation, Sam and Eric. Their names are marked up with <code>dt</code> and what they said is placed in <code>dd</code>. Wrap it all up in a the fresh <code>dialog</code>, and you have a semantically marked up conversation!</p>
<p>Once your sides have stopped splitting, I&#8217;d like to direct you to something a little more complex: how <a href="http://twitter.com">Twitter</a> can take advantage of <code>dialog</code>.</p>
<h3>A Twitter Conversation</h3>
<p>Twitter is a prime example of where <code>dialog</code> can be used in the real world. When a user posts a tweet, other users can reply by starting their tweet with @username, where username is whoever they are responding to.</p>
<pre><code>&lt;dialog&gt;
  &lt;dt&gt;&lt;a href="http://twitter.com/akamike"&gt;@akamike&lt;/a&gt;, &lt;time datetime="2009-08-11T12:35:54"&gt;13 minutes ago&lt;/time&gt;&lt;/dt&gt;
  &lt;dd&gt;Where is a good place to eat in town?&lt;/dd&gt;
  &lt;dt&gt;&lt;a href="http://twitter.com/brucel"&gt;@brucel&lt;/a&gt;, &lt;time datetime="2009-08-11T12:37:56"&gt;11 minutes ago&lt;/time&gt;&lt;/dt&gt;
  &lt;dd&gt;&lt;a href="http://twitter.com/akamike"&gt;@akamike&lt;/a&gt; Have your tried The Swine's Flu pub lunches?&lt;/dd&gt;
  &lt;dt&gt;&lt;a href="http://twitter.com/Rich_Clark"&gt;@Rich_Clark&lt;/a&gt;, &lt;time datetime="2009-08-11T12:38:04"&gt;11 minutes ago&lt;/time&gt;&lt;/dt&gt;
  &lt;dd&gt;&lt;a href="http://twitter.com/akamike"&gt;@akamike&lt;/a&gt; If you like seafood, try the restaurants at the waterfront&lt;/dd&gt;
  &lt;dt&gt;&lt;a href="http://twitter.com/jackosborne"&gt;@jackosborne&lt;/a&gt;, &lt;time datetime="2009-08-11T12:40:02"&gt;9 minutes ago&lt;/time&gt;&lt;/dt&gt;
  &lt;dd&gt;&lt;a href="http://twitter.com/akamike"&gt;@akamike&lt;/a&gt; What &lt;a href="http://twitter.com/brucel"&gt;@brucel&lt;/a&gt; said, or there are lots of good bakeries on the high street.&lt;/dd&gt;
  &lt;dt&gt;&lt;a href="http://twitter.com/spambot148"&gt;@spambot148&lt;/a&gt;, &lt;time datetime="2009-08-11T12:45:16"&gt;4 minutes ago&lt;/time&gt;&lt;/dt&gt;
  &lt;dd&gt;&lt;a href="http://twitter.com/akamike"&gt;@akamike&lt;/a&gt; Gain 1000 followers in 5 minutes!&lt;/dd&gt;
&lt;/dialog&gt;
</code></pre>
<p><a href="http://jsbin.com/obazi">View a live example</a></p>
<p>Here, I have marked up an example of a conversation on Twitter, with users replying to the original speakers tweet. Once again, each person has had their name marked up in a <code>dt</code> but also uses the new <code>time</code> element to define the time of the tweet. In the new <a href="http://dev.w3.org/html5/spec/Overview.html#the-dt-element">definition</a> of <code>dt</code>, there is an example of using <code>time</code> this. Finally, the content of each tweet is placed in a <code>dd</code>. This shows how <code>dialog</code> could be used today in even some of the most popular services on the web.</p>
<h2>Wrapping up</h2>
<p><code>dialog</code> is quite an easy element to grasp, and you&#8217;ll quickly find yourself marking up conversations, chat logs and more with this new element. As seen with the Twitter example, there is scope to add extra value to dialogue used in the real world. Now, go forth and have conversations knowing that you can easily mark them up in HTML 5!
<div id="crp_related">
<h3>Related Posts:</h3>
<ul class="related">
<li><a href="http://html5doctor.com/the-dl-element/" rel="bookmark" class="crp_title">The dl element</a></li>
<li><a href="http://html5doctor.com/your-questions-18/" rel="bookmark" class="crp_title">Your Questions 18</a></li>
<li><a href="http://html5doctor.com/september-html5-spec-changes/" rel="bookmark" class="crp_title">September HTML5 spec changes</a></li>
<li><a href="http://html5doctor.com/the-hgroup-hokey-cokey/" rel="bookmark" class="crp_title">The hgroup hokey cokey</a></li>
<li><a href="http://html5doctor.com/blockquote-q-cite/" rel="bookmark" class="crp_title">Quoting and citing with <code>&lt;blockquote&gt;</code>, <code>&lt;q&gt;</code>, <code>&lt;cite&gt;</code>, and the cite attribute</a></li>
</ul>
</div>
<p><a href="http://html5doctor.com/a-little-more-conversation-with-dialog/" rel="bookmark">A little more conversation with dialog</a> originally appeared on <a href="http://html5doctor.com">HTML5 Doctor</a> on August 12, 2009.</p>
]]></content:encoded>
			<wfw:commentRss>http://html5doctor.com/a-little-more-conversation-with-dialog/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>Understanding aside</title>
		<link>http://html5doctor.com/understanding-aside/</link>
		<comments>http://html5doctor.com/understanding-aside/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 13:00:21 +0000</pubDate>
		<dc:creator>Mike Robinson</dc:creator>
				<category><![CDATA[Elements]]></category>
		<category><![CDATA[article]]></category>
		<category><![CDATA[aside]]></category>
		<category><![CDATA[HTML 5]]></category>

		<guid isPermaLink="false">http://html5doctor.com/?p=154</guid>
		<description><![CDATA[HTML 5 offers a new element to mark additional information that can enhance an article but isn&#8217;t necessarily key to understanding it. However, in the interpretation of &#60;aside&#62; there lies confusion as to how it can be used, and with that there is demand for the Doctor to step up and clear the air. In [...]]]></description>
			<content:encoded><![CDATA[<p><abbr title="Hypertext Mark-up Language">HTML</abbr> 5 offers a new element to mark additional information that can enhance an article but isn&#8217;t necessarily key to understanding it. However, in the interpretation of <code>&lt;aside&gt;</code> there lies confusion as to how it can be used, and with that there is demand for the Doctor to step up and clear the air. In this article I will look at what <code>&lt;aside&gt;</code> was created for, including sample uses and how not to use this useful, misunderstood element.<span id="more-154"></span></p>
<p>First, a look at how the HTML 5 specification defines <code>&lt;aside&gt;</code>:</p>
<blockquote><p>The aside element represents a section of a page that consists of content that is tangentially related to the content around the aside element, and which could be considered separate from that content. Such sections are often represented as sidebars in printed typography.</p></blockquote>
<p>What can often trip-up someone reading the specification is the use of the word &#8220;sidebar&#8221;. I will go into detail about this later in the article, for now you should be aware that what is said there might not quite mean what you first think. Content within an <code>&lt;aside&gt;</code> should be stand-alone information that is related to the article in context. If your <code>&lt;aside&gt;</code> content meets this requirement, then you have a useful element to not only semantically wrap that content but to even hook <abbr title="Cascading Style Sheet">CSS</abbr> styles on.</p>
<p>How strict should this relationship be? Very. Good <code>&lt;aside&gt;</code> content examples include pull-quotes, a glossary or even related links.</p>
<h2>Example Uses</h2>
<p>As suggested in the specification, a pull-quote is an excellent example of a piece of content that is separate from the main article body but still related. Points of interest highlighted.</p>
<pre><code>&lt;article&gt;
    &lt;header&gt;
        &lt;h1&gt;Lorem Ipsum Dolor Sit Amets&lt;/h1&gt;
    &lt;/header&gt;
    &lt;p&gt;Aliquam erat volutpat. Vestibulum eleifend pellentesque urna, at
    sodales est faucibus sit amet. Praesent in mi dui. <strong>&lt;q&gt;Aliquam sed
    bibendum nisl. Mauris pharetra enim sit amet ipsum dictum placerat. Sed
    lacinia pulvinar iaculis. Nam sit amet hendrerit purus.&lt;/q&gt;</strong> Sed a urna
    laoreet lorem pulvinar fermentum. Aenean vel luctus libero. Ut tincidunt
    metus sagittis ante viverra feugiat.&lt;/p&gt;
    <strong>&lt;aside&gt;
        &lt;q&gt;Mauris pharetra enim sit amet ipsum dictum placerat.&lt;/q&gt;
    &lt;/aside&gt;</strong>
    &lt;p&gt;Nulla quis lacus non quam luctus vestibulum. Pellentesque imperdiet
    risus gravida ante consectetur fermentum. Vivamus et est nec risus volutpat
    elementum. Ut faucibus, lectus consectetur volutpat dapibus, quam diam
    luctus enim, vitae mollis enim purus non ante.&lt;/p&gt;
&lt;/article&gt;</code></pre>
<p>For more about the <code>&lt;header&gt;</code> element see Richard&#8217;s article, &#8220;<a href="http://html5doctor.com/the-header-element/">The &lt;header&gt; Element</a>.</p>
<p>On a styled web page or, more common, in a printed article this would be represented visually as a highlighted quote to the side of the main article. This <code>&lt;aside&gt;</code> is related to the content but does not need to be part of the article body as it can be understood without the extra information, or in this case without the duplicate quote.</p>
<p>Another example would be a glossary of terminologies used in an article:</p>
<pre><code>&lt;article&gt;
    &lt;header&gt;
        &lt;h1&gt;Web Technologies&lt;/h1&gt;
    &lt;/header&gt;
    &lt;p&gt;Curabitur dignissim lorem a <strong>CSS</strong> diam posuere tempor. Nam hendrerit,
    eros vel condimentum tempor, ipsum justo cursus justo, quis vestibulum
    turpis turpis sit amet tellus. Quisque quis <strong>PHP</strong> magna eget ipsum faucibus
    bibendum at non diam. Sed sapien est, cursus ac ullamcorper id, egestas vel
    urna <strong>JavaScript</strong>. Nullam aliquam dolor vitae quam pharetra auctor.&lt;/p&gt;
    &lt;aside&gt;
        &lt;dl&gt;
            &lt;dt&gt;CSS&lt;/dt&gt;
            &lt;dd&gt;A set of standards for styling documents presented on the
            World Wide Web.&lt;/dd&gt;
            &lt;dt&gt;PHP&lt;/dt&gt;
            &lt;dd&gt;A server-side scripting language suited to dynamic HTML document
            generation for the web.&lt;/dd&gt;
            &lt;dt&gt;JavaScript&lt;/dt&gt;
            &lt;dd&gt;A client-side scripting language used for manipulating HTML documents
            within a browser.&lt;/dd&gt;
        &lt;/dl&gt;
    &lt;/aside&gt;
&lt;/article&gt;</code></pre>
<h2>Incorrect use of <code>&lt;aside&gt;</code></h2>
<p>It is easy to confuse this element for something it isn&#8217;t, and as mentioned earlier the definition of <code>&lt;aside&gt;</code> can trip-up a few developers. The most common misconception of how this element should be used is for the standard sidebar. While there is usually a degree of relation between sidebar content and the content in an article, it is not enough to be considered fit for an <code>&lt;aside&gt;</code>. Navigation, ads, search boxes, blogrolls and so on are not directly related to the article and therefore do not justify the use of an <code>&lt;aside&gt;</code>.</p>
<p>In the definition of <code>&lt;aside&gt;</code> it is key to note that it refers to sidebars in printed media, such as a magazine or leaflet. A &#8220;sidebar&#8221; in a magazine might contain additional notes on the article in context, translating this to HTML 5 would consider this an <code>&lt;aside&gt;</code>. If the printed article on <abbr title="Hypertext Pre-Processor">PHP</abbr> had an ad for &#8220;Superior, Cheap, Web Hosting&#8221; as a sidebar, this would not be classified as an <code>&lt;aside&gt;</code>. In such cases, look at other elements for more semantic mark-up.</p>
<h2>Closing Thoughts</h2>
<p>Like any HTML element, when used correctly the <code>&lt;aside&gt;</code> element can be very useful in semantically marking-up page content. An <code>&lt;aside&gt;</code> can be used to enhance an article with additional information, or highlighting parts that the reader may find interesting. Asides are stand-alone, non-essential as part of an article but when used correctly it can be an extra level of information for your content. Don&#8217;t try to force content into an <code>&lt;aside&gt;</code>, if it&#8217;s not tangentially related to the article then it shouldn&#8217;t be there. HTML 5 offers many new elements to mark-up your web pages, use them wisely.
<div id="crp_related">
<h3>Related Posts:</h3>
<ul class="related">
<li><a href="http://html5doctor.com/aside-revisited/" rel="bookmark" class="crp_title">Aside Revisited</a></li>
<li><a href="http://html5doctor.com/you-can-still-use-div/" rel="bookmark" class="crp_title">You can still use div</a></li>
<li><a href="http://html5doctor.com/the-details-and-summary-elements/" rel="bookmark" class="crp_title">The details and summary elements</a></li>
<li><a href="http://html5doctor.com/the-hgroup-element/" rel="bookmark" class="crp_title">The hgroup element</a></li>
<li><a href="http://html5doctor.com/your-questions-16/" rel="bookmark" class="crp_title">Your Questions #16</a></li>
</ul>
</div>
<p><a href="http://html5doctor.com/understanding-aside/" rel="bookmark">Understanding aside</a> originally appeared on <a href="http://html5doctor.com">HTML5 Doctor</a> on June 19, 2009.</p>
]]></content:encoded>
			<wfw:commentRss>http://html5doctor.com/understanding-aside/feed/</wfw:commentRss>
		<slash:comments>61</slash:comments>
		</item>
	</channel>
</rss>

