<?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>San Bei Ji &#187; Web Development</title>
	<atom:link href="http://www.sanbeiji.com/archives/category/web-development/feed" rel="self" type="application/rss+xml" />
	<link>http://www.sanbeiji.com</link>
	<description>三杯雞好吃!</description>
	<lastBuildDate>Wed, 18 Jan 2012 17:57:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Coloring the HR element line in CSS</title>
		<link>http://www.sanbeiji.com/archives/1307</link>
		<comments>http://www.sanbeiji.com/archives/1307#comments</comments>
		<pubDate>Wed, 07 Dec 2011 00:37:31 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[border-color]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[hr]]></category>
		<category><![CDATA[html5]]></category>

		<guid isPermaLink="false">http://www.sanbeiji.com/?p=1307</guid>
		<description><![CDATA[I never, ever use this element, but HR has been bequeathed new life in HTML5 and I may start using it for providing more thematic break awesomeness to my already blindingly-awesome prose and poetry. Anyway, someone asked me this question: &#8230; <a href="http://www.sanbeiji.com/archives/1307">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_brick-red" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Fwww.sanbeiji.com%252Farchives%252F1307%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22Coloring%20the%20HR%20element%20line%20in%20CSS%22%20%7D);"></div>
<p>I never, ever use this element, but <a href="http://dev.w3.org/html5/markup/hr.html">HR has been bequeathed new life in HTML5</a> and I may start using it for providing more thematic break awesomeness to my already blindingly-awesome prose and poetry.</p>
<p>Anyway, someone asked me this question: Is color supported in all browsers by the HR element? To which I replied: &#8220;I have no clue. Let me investigate.&#8221;</p>
<p>Here&#8217;s an initial test:</p>
<p><code><br />
&lt;!DOCTYPE html&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;meta charset=&quot;utf-8&quot;&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;title&gt;HR colors I have known...&lt;/title&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;style type=&quot;text/css&quot; media=&quot;screen&quot;&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.blue {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;color:blue;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.red {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;border-color:red;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/style&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;blue:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;hr class=&quot;blue&quot;&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;red:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;hr class=&quot;red&quot;&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;green:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;hr color=&quot;green&quot;&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
</code></p>
<p>Well hambone. Using the text rule for color on WebKit browsers yields no color change. Works fine in all cases in Firefox. IE gives no quarter to the border-color CSS property, but works fine with the text color value. Every browser supports HTML color attributes, but you know that using presentational markup is as wrong as Michelle Bachmann&#8217;s views on <a href="http://scienceblogs.com/pharyngula/2006/10/bachmann_on_id.php">evolution</a> and <a href="http://scienceblogs.com/pharyngula/2011/09/michele_bachmann_pseudo-scient.php">vaccination</a>, so you just say no.</p>
<p>So what&#8217;s a poor web dev to do? Define a border width:</p>
<p><code><br />
.red {<br />
&nbsp;&nbsp;&nbsp;&nbsp;border:none;<br />
&nbsp;&nbsp;&nbsp;&nbsp;border-bottom:thin solid red;<br />
}<br />
</code></p>
<p>Replacing the original border-color rule with the shorthand listed here, or just providing an explicit border-width property, will render a consistent 2 pixel line in all browsers. If we just wrote something like border:thin solid red; we&#8217;d get a 2-pixel border &#8211; see you&#8217;d think the HR element is just a line, but in fact the browsers all treat it like a box it seems. So we have to clear it out with border:none; and then add a border-bottom or border-top rule to set a 1 pixel line. If you want different widths, you have arguably more accurate control by only having to argue with one border instead of two.</p>
<p>What&#8230; you want to replace that HR with a background image? Good idea. <a href="http://blog.neatlysliced.com/2008/03/hr-image-replacement/">Check out this post at Neatly Sliced for the answer</a>, and gird your loins for the usual IE kludgeries.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.sanbeiji.com/archives/1307/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A quick book review: Responsive Web Design</title>
		<link>http://www.sanbeiji.com/archives/1304</link>
		<comments>http://www.sanbeiji.com/archives/1304#comments</comments>
		<pubDate>Mon, 14 Nov 2011 19:30:57 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[Books]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[responsive]]></category>

		<guid isPermaLink="false">http://www.sanbeiji.com/?p=1304</guid>
		<description><![CDATA[Just finished reading an excellent book: &#8220;Responsive Web Design&#8221; by Ethan Marcotte. If you build web pages, I want you to read this book. Here&#8217;s a few of my thoughts on what I just learned, and why you should read &#8230; <a href="http://www.sanbeiji.com/archives/1304">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_brick-red" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Fwww.sanbeiji.com%252Farchives%252F1304%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22A%20quick%20book%20review%3A%20Responsive%20Web%20Design%22%20%7D);"></div>
<p>Just finished reading an excellent book: &#8220;<a href="http://www.abookapart.com/products/responsive-web-design" title="A Book Apart, Responsive Web Design">Responsive Web Design</a>&#8221; by <a href="http://unstoppablerobotninja.com/" title="The Unstoppable Robot Ninja">Ethan Marcotte</a>. If you build web pages, I want you to read this book. Here&#8217;s a few of my thoughts on what I just learned, and why you should read this one too.</p>
<p>The book begins with an overview of the evolution of page layout in web design, starting with it&#8217;s roots in printed page design and moving on to today&#8217;s reality that there is a multitude of screens and devices out there, with more on the way. We cannot predict what type of device our readers will show up with, and must adjust our belief system (if we have one) to accommodate the new realities that the various screen widths and mobile device sizes present us with.</p>
<p>The second chapter discusses the idea of designing within the constraints of a flexible typographic grid. Grid systems are somewhat of an artificial constraint that designers place on themselves to provide balance and symmetry to page layout, and on screen a new challenge is presented in that the page size is no longer fixed. The main takeaway here is to design content in flexible porportions to the variable screen widths that might be used to access your web pages. Mr. Marcotte puts forth some simple, accessible ideas for developers to leverage, making text more readable on unknown devices by putting forth a formula that I&#8217;ll repeat here mostly for the purposes of getting my own head wrapped around it:</p>
<p><code>target ÷ context = result</code></p>
<p>To decode Mr. Marcotte&#8217;s example, he begins with an assumption of a base font size of 16px. The headline in the comp is defined to be 24px. So to make it flexible, divide:</p>
<p><code>24 ÷ 16 = 1.5</code></p>
<p>And so the headline should be defined as 1.5em. Simple and elegant rule of thumb. Now we just need to remember to do it.</p>
<p>Chapter 3 applies this principle to flexible images, and expands upon it. There is the inevitable Questionable Functionality Challenge™ presented to us by Internet Explorer, which is quickly defused. That&#8217;s a lot of ink to dedicate to an obsolete web browser and the example demonstrates where the real problem lies by showing how awful text looks in resized images. But you aren&#8217;t locking up text in your images, right? I know, I know, it&#8217;s an academic example and clearly illustrates the failings of IE&#8217;s image resize capabilities. Let&#8217;s move on.</p>
<p>Chapter 4 introduces media queries. We&#8217;re finally at what I consider to be the coolest and most important part of the book &#8211; how to progressively enhance your web page layouts through the media query construct. Mr. Marcotte makes the argument in favor of using the min-width property instead of things like max-width (which tends to yield excessive code) and min-device-width (which only pertains to devices and doesn&#8217;t take into account variable web browser windows.) The max-width property is introduced for those that want to stop the insanity. (I do know people that expand their web browser to the full width of their 27&#8243; high resolution monitors.)</p>
<p>Chapter 5 pulls it all together with strategies to integrate responsive design into your team&#8217;s workflow; how to make your design process itself a responsive one. He builds the case for <a href="http://www.lukew.com/">Luke Wroblewski</a>&#8216;s &#8220;<a href="http://www.lukew.com/ff/entry.asp?933">Mobile First</a>&#8221; philosophy (a case that was already built up a bit in chapter 1) and finishes it all of with how to incorporate progressive enhancement using JavaScript to selectively pull in a slideshow component only when JavaScript is available and all the stars are in the proper alignment.</p>
<p>Overall, my belief has always been somewhat of the philosophy that there should be just &#8220;one web&#8221;; no &#8220;mobile web&#8221; or any other sort of alternate web reality that we should somehow slip into. Today&#8217;s mobile devices that are in fact being used to access the web are billed as fully capable web browsing devices, and indeed they are. Why deliver a shrunken-down version of your website just because they have a 3&#8243; wide screen these days? It no longer makes sense in most cases; just reposition your content to accommodate their view. Every chapter includes simple, usable techniques that work, and I feel that these gems of advice should be a core part your future projects.</p>
<p>Lastly, I am very thankful for the appearance of the <a href="http://www.abookapart.com/">A Book Apart</a> series. Each one of these volumes is, I believe, how a tech book should be: concise, full of valuable, practical, actionable information. I have read several of these so far, and each one has been a hit. I look forward to more.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.sanbeiji.com/archives/1304/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Annotate your Rails model</title>
		<link>http://www.sanbeiji.com/archives/1292</link>
		<comments>http://www.sanbeiji.com/archives/1292#comments</comments>
		<pubDate>Fri, 11 Nov 2011 20:19:37 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[gems]]></category>
		<category><![CDATA[models]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[schema]]></category>

		<guid isPermaLink="false">http://www.sanbeiji.com/?p=1292</guid>
		<description><![CDATA[I just discovered this handy little gem called annotate. Run it and it&#8217;ll insert a comment in all of your model files at once, outlining the schema. This is incredibly convenient when working with your Rails models to be able &#8230; <a href="http://www.sanbeiji.com/archives/1292">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_brick-red" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Fwww.sanbeiji.com%252Farchives%252F1292%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22Annotate%20your%20Rails%20model%22%20%7D);"></div>
<p>I just discovered this handy little gem called <a href="https://github.com/ctran/annotate_models" title="The annotate_models gem on GitHub">annotate</a>. Run it and it&#8217;ll insert a comment in all of your model files at once, outlining the schema. This is incredibly convenient when working with your Rails models to be able to see the data and types right there in the top of the file.</p>
<p>Here&#8217;s what my Noober (/app/models/noober.rb) model looks like by default:</p>
<pre class="brush: ruby">
class Noober < ActiveRecord::Base
end
</pre>
<p>Spartan as always. Let's give ourselves something to look at with the <em>annotate</em> command. First, include annotate in your Rails 3 project in the Gemfile:</p>
</pre>
<pre class="brush: ruby">
group :development do
  ...
  gem 'annotate'
end
</pre>
<p>Run the install command to update your gems:</p>
<pre class="brush: bash">$ bundle install</pre>
<p>Run it from within your project directory:</p>
<pre class="brush: bash">$ bundle exec annotate --position before
Annotated (1): Noober</pre>
<p>And the result should look something like this in your models:</p>
<pre class="brush: ruby">
# == Schema Information
#
# Table name: noobers
#
#  id         :integer         not null, primary key
#  firstname  :string(255)
#  lastname   :string(255)
#  email      :string(255)
#  nooblevel  :integer
#  created_at :datetime
#  updated_at :datetime
#

class Noober < ActiveRecord::Base
end
</pre>
<p>Awesome! Now I can see quickly which parts of the model I need to work with and add my code without having to peek at the database:</p>
</pre>
<pre class="brush: bash">
# == Schema Information
#
# Table name: noobers
#
#  id         :integer         not null, primary key
#  firstname  :string(255)
#  lastname   :string(255)
#  email      :string(255)
#  nooblevel  :integer
#  created_at :datetime
#  updated_at :datetime
#

class Noober < ActiveRecord::Base
    attr_accessible :firstname, :lastname, :email
    validates :firstname,  :presence => true
    validates :lastname, :presence => true
    validates :email, :presence => true
end
</pre>
<p>Works well for me!</p>

]]></content:encoded>
			<wfw:commentRss>http://www.sanbeiji.com/archives/1292/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>When Can I Use posts a usage table</title>
		<link>http://www.sanbeiji.com/archives/1276</link>
		<comments>http://www.sanbeiji.com/archives/1276#comments</comments>
		<pubDate>Mon, 19 Sep 2011 15:50:19 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[browsers]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[Safari]]></category>

		<guid isPermaLink="false">http://www.sanbeiji.com/?p=1276</guid>
		<description><![CDATA[When Can I Use has posted a nice browser usage table, which includes mobile browsers and a breakdown by browser version. Compared with the browser market share analysis at Wikipedia, the numbers do line up quite well for the major &#8230; <a href="http://www.sanbeiji.com/archives/1276">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_brick-red" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Fwww.sanbeiji.com%252Farchives%252F1276%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22When%20Can%20I%20Use%20posts%20a%20usage%20table%22%20%7D);"></div>
<p>When Can I Use has posted a nice <a href='http://caniuse.com/usage_table.php'>browser usage table</a>, which includes mobile browsers and a breakdown by browser version. Compared with the <a href="http://en.wikipedia.org/wiki/Browser_market_share">browser market share analysis at Wikipedia</a>, the numbers do line up quite well for the major categories, although there are some interesting discrepancies when you get down into the weeds.</p>
<p>I love looking at statistics and seeing what jumps out at you. What I see from these numbers today, here in September of 2011, is this:</p>
<ul>
<li>IE is only 39% of browser market share now. Remember ten years ago? Yeah, times have changed.</li>
<li>Chrome is doing quite well. It&#8217;s going to overtake Firefox at this rate. 21% &#8211; that&#8217;s amazing.</li>
<li>Going by the When Can I Use analysis, if you combine Chrome, Safari, iOS, and Android, you have about 29% market share for WebKit browsers.</li>
<li>If these trends continue, and I see every indication that they will, Google Chrome will become the dominant browser platform sometime in the first half of 2012.</li>
</ul>
<p>Fascinating. I&#8217;m going to need to make more popcorn.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.sanbeiji.com/archives/1276/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Some Google+ thoughts</title>
		<link>http://www.sanbeiji.com/archives/1269</link>
		<comments>http://www.sanbeiji.com/archives/1269#comments</comments>
		<pubDate>Wed, 27 Jul 2011 18:33:55 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[social networks]]></category>

		<guid isPermaLink="false">http://www.sanbeiji.com/?p=1269</guid>
		<description><![CDATA[No question, Google+ is Google&#8217;s most successful foray into the whole social media arena. I am sure this one will succeed where other initiatives have failed. I&#8217;m glad to see it taking off. But a few things need to be &#8230; <a href="http://www.sanbeiji.com/archives/1269">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_brick-red" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Fwww.sanbeiji.com%252Farchives%252F1269%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22Some%20Google%2B%20thoughts%22%20%7D);"></div>
<p>No question, Google+ is Google&#8217;s most successful foray into the whole social media arena. I am sure this one will succeed where other initiatives have failed. I&#8217;m glad to see it taking off. But a few things need to be worked out for it to achieve it&#8217;s full potential. Here&#8217;s my unsolicited feedback:</p>
<p>I think the first thing I&#8217;d like to see is for all my Buzz content to go directly into my stream. I don&#8217;t want two streams, nor do I want to go look at a separate place for all the people I follow on Buzz vs. Google+. It is an extra step that I don&#8217;t have time to take.</p>
<p>Another thing I&#8217;d like to see is that my activity stream selection should remain persistent. Currently the default stream is for everybody in my circles, but I would much rather have that be filtered to whatever circle I choose or was last viewing.</p>
<p>In fact, get rid of Buzz. And figure out how Google Reader and Google Bookmarks play in with this. Integrate them, or get rid of any overlap or confusion. Do it now before the problems become worse. Don&#8217;t wait.</p>
<p>I would really like a way to have my Twitter posts show up in my Google+ stream. This again is a time issue &#8211; I don&#8217;t want to spend a lot of time tending my content on both networks. It&#8217;s largely the same crowd for me anyway. If I have a choice between one or the other, I&#8217;m going to spend the time on Twitter because that&#8217;s where most of my contacts are. On the other hand if my content is posted in both places, then I can see if there are responses and alerts in the Google nav bar whenever I&#8217;m using Gmail or Calendar, which would be fine.</p>
<p>The toolbar changes lists links for Web, Images, Videos, Maps, and News if I&#8217;m looking at one of those properties, and Calendar, Documents, Photos, and Reader if I&#8217;m in one of those areas. Gmail and Web are listed in both, although the Gmail toolbar uses the docs/photos/reader listing (inexplicably in gray instead of black I might add) and Web lists the web/images/videos set. Sometimes links open in new windows. Sometimes they don&#8217;t. Who knows or cares what will happen next? I&#8217;m feeling lucky! Sigh.</p>
<p>The mobile version of the site doesn&#8217;t let me +1 comments. Overall I&#8217;d like to see more functionality built in to the mobile version of the site.</p>
<p>The mobile app on iOS seems like an early beta. I opted out of using geolocation when I first launched it and now there&#8217;s no way to get it back.</p>
<p>There it is &#8211; my loving feedback. Fix all that and I will be back. xoxox -J.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.sanbeiji.com/archives/1269/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SVG and MathML in HTML5</title>
		<link>http://www.sanbeiji.com/archives/1243</link>
		<comments>http://www.sanbeiji.com/archives/1243#comments</comments>
		<pubDate>Wed, 08 Dec 2010 04:51:09 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[developingwithhtml5]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[MathML]]></category>
		<category><![CDATA[science]]></category>
		<category><![CDATA[standards]]></category>
		<category><![CDATA[svg]]></category>
		<category><![CDATA[webdev]]></category>
		<category><![CDATA[webstandards]]></category>

		<guid isPermaLink="false">http://www.sanbeiji.com/?p=1243</guid>
		<description><![CDATA[The next article in the Developing with HTML5 series. Pick a flower on Earth and you move the farthest star. —Paul Dirac Scalable Vector Graphics (SVG) and MathML are XML applications that are widely used in scientific contexts. SVG is &#8230; <a href="http://www.sanbeiji.com/archives/1243">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_brick-red" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Fwww.sanbeiji.com%252Farchives%252F1243%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22SVG%20and%20MathML%20in%20HTML5%22%20%7D);"></div>
<p><em>The next article in the <a href="http://www.sanbeiji.com/archives/tag/developingwithhtml5">Developing with HTML5 series</a>.</em></p>
<blockquote><p>Pick a flower on Earth and you move the farthest star. </p>
<p><cite>—Paul Dirac</cite></p></blockquote>
<p><a href="http://en.wikipedia.org/wiki/Scalable_Vector_Graphics">Scalable Vector Graphics</a> (SVG) and <a href="http://www.w3.org/Math/">MathML</a> are XML applications that are widely used in scientific contexts. SVG is used to draw vector graphics, and is frequently found in visualization libraries such as <a href="http://vis.stanford.edu/protovis/">ProtoVis</a>. MathML is used to describe the presentation and meaning of mathematical formul&aelig;. They are very easy to work with in a programmatic sense, because they are XML-based and therefore just text, and yet they are capable of rendering beautiful information in supporting web browsers.</p>
<div id="attachment_1245" class="wp-caption alignright" style="width: 150px"><a href="http://www.sanbeiji.com/wp-content/uploads/2010/12/Dirac.gif" rel="lightbox[1243]"><img src="http://www.sanbeiji.com/wp-content/uploads/2010/12/Dirac.gif" alt="Paul Dirac, who loved the maths." title="Dirac" width="140" height="198" class="size-full wp-image-1245" /></a><p class="wp-caption-text">Paul Dirac, who loved the maths.</p></div>
<p>The idea behind XHTML was to move the web toward extensibility (the X in XHTML), where a web browser markup language could be seeded with bits of other XML applications by declaring a namespace and letting things coexist. The problem with that plan was that XML parsers were required to be extremely fussy, to the point that if a problem was detected the browser should render an error message. Browsers don&#8217;t work that way. Instead, they forgive your human or computer errors and render the page as best as their little hearts can.</p>
<p>In the beginning of the process, HTML5 was not extensible, and to this day it remains opposed to the whole namespace idea. But SVG and MathML are highly popular and useful XML applications that deserve a place within the HTML5 spec. And so shall it be: <code>&lt;svg&gt;</code> and <code>&lt;math&gt;</code> are the opening volleys in inserting SVG and MathML into your HTML5 document tree. Any elements that are children of the SVG and MathML specs are valid and functional child elements of the <code>&lt;svg&gt;</code> and <code>&lt;math&gt;</code> elements respectively. No need to declare a namespace. You&#8217;re done. Thank you.</p>
<p>Now this is not to say that the idea of inserting these XML applications within the HTML5 spec is not without some controversy. What about <a href="http://en.wikipedia.org/wiki/List_of_XML_markup_languages">other XML applications</a> and XHTML extensions such as <a href="http://en.wikipedia.org/wiki/RDFa">RDFa</a>, <a href="http://en.wikipedia.org/wiki/Chemical_Markup_Language">CML</a>, and <a href="http://www.musicmarkup.info/">MML</a>? CML (Chemical Markup Language) and MML (Music Markup Language) are indeed common, but within specific application contexts. They are not supported yet by any web browser (whereas MathML and SVG are well supported.) RDFa on the other hand is a more political issue: More on that whole mess in a later post&#8230; <img src='http://www.sanbeiji.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>So in short, SVG and MathML are supported objects within HTML5 because they are widely deployed in existing web browsers, and they are very useful – particularly to those of us in the science industry charged with representing scientific information on the web. Let&#8217;s look at how to get started. First, an SVG example – simply start your SVG block using the <code>&lt;svg&gt;</code> element and drop your SVG markup within:</p>
<p><code>&lt;!DOCTYPE&nbsp;html&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
&nbsp;&nbsp;&lt;meta&nbsp;charset=&quot;utf-8&quot;&gt;<br />
&nbsp;&nbsp;&lt;title&gt;The Sun in SVG&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&nbsp;&nbsp;&lt;h1&gt;The Sun in SVG&lt;/h1&gt;<br />
&nbsp;&nbsp;&lt;svg&nbsp;style=&quot;width:300px;&nbsp;height:300px;&quot;&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;radialGradient&nbsp;cx=&quot;0.5&quot;&nbsp;cy=&quot;0.5&quot;&nbsp;r=&quot;0.5&quot;&nbsp;id=&quot;g&quot;&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;stop&nbsp;stop-color=&quot;rgb(255,&nbsp;255,&nbsp;0)&quot;&nbsp;offset=&quot;0&quot;/&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;stop&nbsp;stop-color=&quot;rgb(255,&nbsp;221,&nbsp;51)&quot;&nbsp;offset=&quot;0.6917&quot;/&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;stop&nbsp;stop-color=&quot;rgb(254,&nbsp;140,&nbsp;25)&quot;&nbsp;offset=&quot;0.7083&quot;/&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;stop&nbsp;stop-color=&quot;rgb(0,&nbsp;0,&nbsp;0)&quot;&nbsp;offset=&quot;1&quot;/&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;/radialGradient&gt;<br />
&nbsp;&nbsp;&nbsp;&lt;rect&nbsp;width=&quot;100%&quot;&nbsp;height=&quot;100%&quot;&nbsp;fill=&quot;url(#g)&quot;/&gt;<br />
&nbsp;&nbsp;&lt;/svg&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</code></p>
<p><a href="/tests/html5_svg_mathml_example.html">Here&#8217;s a live example</a> that will work in browsers that support SVG and MathML in HTML5. (Try it in the Firefox 4 beta.) Or if you aren&#8217;t one of those early-adopting browser users that are used to living dangerously, then please refer to the perfectly safe reference image below:</p>
<div id="attachment_1246" class="wp-caption aligncenter" style="width: 310px"><img src="http://www.sanbeiji.com/wp-content/uploads/2010/12/svgsun.png" alt="Reference rendering of the sun in SVG." width="300" height="300" class="alignnone size-full wp-image-1246" /><p class="wp-caption-text">Reference rendering of the sun in SVG.</p></div>
<p>To learn more about SVG, check out the <a href="http://www.w3schools.com/svg/default.asp">w3schools SVG tutorial</a> for starters.  While SVG is supported in basic forms in Chrome, Safari, and Firefox, only Firefox 4 (currently in beta) supports embedding SVG natively in HTML5. But Chrome will follow soon, followed by IE9, Safari, and eventually (hopefully) Opera.</p>
<p>MathML is equally straightforward, using the <code>&lt;math&gt;</code> element as the opener:</p>
<p><code>&lt;!DOCTYPE html&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
&nbsp;&nbsp;&lt;meta charset=&quot;utf-8&quot;&gt;<br />
&nbsp;&nbsp;&lt;title&gt;The Dirac &amp;delta;-function&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&nbsp;&nbsp;&lt;h1&gt;The Dirac &amp;delta;-function&lt;/h1&gt;<br />
&nbsp;&nbsp;&lt;math style=&quot;font-size:200%&quot;&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;mrow&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;msubsup&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;mo&gt;&amp;int;&lt;/mo&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;mrow&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;mrow&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;mo&gt;-&lt;/mo&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;mi&gt;&amp;infin;&lt;/mi&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/mrow&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/mrow&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;mi&gt;&amp;infin;&lt;/mi&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/msubsup&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;mrow&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;mi&gt;f&lt;/mi&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;mi&gt;&amp;delta;&lt;/mi&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/mrow&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/mrow&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;mo&gt;=&lt;/mo&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;mrow&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;mo&gt;f&lt;/mo&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;mfenced&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;mrow&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;mn&gt;0&lt;/mn&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/mrow&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/mfenced&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/mrow&gt;<br />
&nbsp;&nbsp;&lt;/math&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</code></p>
<p>Compare to the reference rendering below, or <a href="/tests/html5_svg_mathml_example.html">check out the live example</a>.</p>
<div id="attachment_1247" class="wp-caption alignnone" style="width: 194px"><a href="http://www.sanbeiji.com/wp-content/uploads/2010/12/dirac-delta.png" rel="lightbox[1243]"><img src="http://www.sanbeiji.com/wp-content/uploads/2010/12/dirac-delta.png" alt="The Dirac delta function rendered from MathML in Firefox 4 beta" title="dirac-delta" width="184" height="55" class="size-full wp-image-1247" /></a><p class="wp-caption-text">The Dirac delta function rendered from MathML in Firefox 4 beta</p></div>
<p>Again, currently Firefox 4 beta is the only close-to-shipping browser that supports this. But it is expected to come to all major modern browsers in 2010/2011, including IE9, Safari, Opera, and Google Chrome. To learn more about how to construct MathML, check out <a href="http://reference.wolfram.com/mathematica/XML/tutorial/MathML.html">Mathematica&#8217;s MathML tutorial</a>.</p>
<p>In short, it&#8217;s an easy trip to embed SVG and MathML in HTML5. No namespaces are required. The trade-off is less extensibility, but if you need extensibility back there&#8217;s an XML flavor of HTML5, appropriately titled <a href="http://blog.whatwg.org/xhtml5-in-a-nutshell">XHTML5</a>. In the meantime, start looking for ways to leverage SVG and MathML in the coming months as capable browsers start coming online! While this is indeed a bit on the bleeding-edge side of things, web browsers are beginning to implement these features and I expect over the next year or two the practice of embedding SVG and MathML markup in HTML5 web pages will become entirely commonplace within the scientific community.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.sanbeiji.com/archives/1243/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Exploring New HTML5 Elements</title>
		<link>http://www.sanbeiji.com/archives/1237</link>
		<comments>http://www.sanbeiji.com/archives/1237#comments</comments>
		<pubDate>Fri, 03 Dec 2010 18:19:36 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[developingwithhtml5]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[semantics]]></category>
		<category><![CDATA[structure]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://www.sanbeiji.com/?p=1237</guid>
		<description><![CDATA[The next article in the Developing with HTML5 series. Nothing endures but change. —Heraclitus The HTML5 draft specification includes many new elements and attributes for enhanced structural and semantic clarity. Most of the old elements still exist too, and you &#8230; <a href="http://www.sanbeiji.com/archives/1237">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_brick-red" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Fwww.sanbeiji.com%252Farchives%252F1237%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22Exploring%20New%20HTML5%20Elements%22%20%7D);"></div>
<p><em>The next article in the <a href="http://www.sanbeiji.com/archives/tag/developingwithhtml5">Developing with HTML5 series</a>.</em></p>
<blockquote><p>Nothing endures but change.</p>
<p><em>—Heraclitus</em></p></blockquote>
<p>The HTML5 draft specification includes many new elements and attributes for enhanced structural and semantic clarity. Most of the old elements still exist too, and you can still use them if you like. But the new elements will serve to make your markup clearer, more compact, and more functional in modern web browsers. Let&#8217;s take a look at some of these elements and what they mean for web developers in scientific contexts. For starters, here&#8217;s a list of the new elements, along with links to the relevant points in the specification:</p>
<div id="attachment_358" class="wp-caption alignright" style="width: 204px"><a href="http://www.flickr.com/photos/cote/146504243/" title="Heraclitus by cote, on Flickr"><img src="http://farm1.static.flickr.com/56/146504243_73bd332c0a_m.jpg" width="194" height="240" alt="Heraclitus" /></a><p class="wp-caption-text">Heraclitus by cote on Flickr</p></div>
<ul>
<li><a href="http://dev.w3.org/html5/spec/forms.html#the-datalist-element"><code>datalist</code></a></li>
<li><a href="http://dev.w3.org/html5/spec/forms.html#the-keygen-element"><code>keygen</code></a></li>
<li><a href="http://dev.w3.org/html5/spec/forms.html#the-output-element"><code>output</code></a></li>
<li><a href="http://dev.w3.org/html5/spec/text-level-semantics.html#the-ruby-element"><code>ruby</code></a>, <a href="http://dev.w3.org/html5/spec/text-level-semantics.html#the-rt-element"><code>rt</code></a>, and <a href="http://dev.w3.org/html5/spec/text-level-semantics.html#the-rp-element"><code>rp</code></a></li>
<li><a href="http://dev.w3.org/html5/spec/text-level-semantics.html#the-wbr-element"><code>wbr</code></a></li>
<li><a href="http://www.w3.org/TR/html5/embedded-content-0.html#the-embed-element"><code>embed</code></a></li>
<li><a href="http://www.w3.org/TR/html5/interactive-elements.html#the-command"><code>command</code></a></li>
<li><a href="http://www.w3.org/TR/html5/interactive-elements.html#the-details-element"><code>details</code></a></li>
<li><a href="http://www.w3.org/TR/html5/semantics.html#the-article-element"><code>article</code></a></li>
<li><a href="http://www.w3.org/TR/html5/semantics.html#the-aside-element"><code>aside</code></a></li>
<li><a href="http://www.w3.org/TR/html5/semantics.html#the-figure-element"><code>figure</code></a></li>
<li><a href="http://www.w3.org/TR/html5/semantics.html#the-footer-element"><code>footer</code></a></li>
<li><a href="http://www.w3.org/TR/html5/semantics.html#the-header-element"><code>header</code></a></li>
<li><a href="http://www.w3.org/TR/html5/semantics.html#the-hgroup-element"><code>hgroup</code></a></li>
<li><a href="http://www.w3.org/TR/html5/semantics.html#the-nav-element"><code>nav</code></a></li>
<li><a href="http://www.w3.org/TR/html5/semantics.html#the-section-element"><code>section</code></a></li>
<li><a href="http://www.w3.org/TR/html5/text-level-semantics.html#the-mark-element"><code>mark</code></a></li>
<li><a href="http://www.w3.org/TR/html5/text-level-semantics.html#the-meter-element"><code>meter</code></a></li>
<li><a href="http://www.w3.org/TR/html5/text-level-semantics.html#the-progress-element"><code>progress</code></a></li>
<li><a href="http://www.w3.org/TR/html5/text-level-semantics.html#the-time-element"><code>time</code></a></li>
<li><a href="http://www.w3.org/TR/html5/the-canvas-element.html#the-canvas-element"><code>canvas</code></a></li>
<li><a href="http://www.w3.org/TR/html5/video.html#video"><code>video</code></a></li>
</ul>
<h3>A first glance at HTML5 structure</h3>
<p>The first elements we should look at are the structural ones: </p>
<p><code>article</code>, <code>aside</code>, <code>figcaption</code>, <code>figure</code>, <code>footer</code>, <code>header</code>, <code>hgroup</code>, <code>nav</code>, and <code>section</code>. Take a look at those names for a moment. Think how many times you&#8217;ve formed your markup in a fashion resembling something like the following code:</p>
<p><code>&lt;div&nbsp;<b>id=&quot;header&quot;</b>&gt;<br />
&nbsp;&nbsp;&lt;h1&gt;Tales&nbsp;of&nbsp;Woe&lt;/h1&gt;<br />
&nbsp;&nbsp;&lt;p&nbsp;class=&quot;tagline&quot;&gt;The&nbsp;neverending&nbsp;saga&nbsp;continues...&lt;/p&gt;<br />
&nbsp;&nbsp;&lt;div&nbsp;<b>id=&quot;nav&quot;</b>&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;h2&gt;Navigation&lt;/h2&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;ul&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;&lt;a&nbsp;href=&quot;one.html&quot;&gt;Page&nbsp;One&lt;/a&gt;&lt;/li&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;&lt;a&nbsp;href=&quot;two.html&quot;&gt;Page&nbsp;Two&lt;/a&gt;&lt;/li&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;&lt;a&nbsp;href=&quot;three.html&quot;&gt;Page&nbsp;the&nbsp;Third&lt;/a&gt;&lt;/li&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/ul&gt;<br />
&nbsp;&nbsp;&lt;/div&gt;<br />
&lt;/div&gt;<br />
&lt;div&nbsp;<b>class=&quot;article&quot;</b>&gt;<br />
&nbsp;&nbsp;&lt;h2&gt;The&nbsp;Stagnant&nbsp;Staircase&lt;/h2&gt;<br />
&nbsp;&nbsp;&lt;p&gt;It was a dark and stormy night. She didn&#x27;t notice the vase by the banister as she walked past it, holding the wilted flowers in stale and murky water. The only thing she knew was that the nightmares had to end, and that they would end tonight...&lt;/p&gt;<br />
&lt;/div&gt;<br />
&lt;div&nbsp;<b>id=&quot;footer&quot;</b>&gt;<br />
&nbsp;&nbsp;&lt;p&gt;&copy;2010&nbsp;In&nbsp;Your&nbsp;Nightmares&nbsp;Productions.&lt;/p&gt;<br />
&lt;/div&gt;</code></p>
<p>In particular, I&#8217;d like to direct your attention to the ID and class attributes for header, article, and footer. These are major structural components that are common in everyday markup. Use of these semantic structures is so common, that it made sense to construct elements around them. Here is the same code as the above, refactored in HTML5:</p>
<p><code><b>&lt;header&gt;</b><br />
&nbsp;&nbsp;&lt;h1&gt;Tales&nbsp;of&nbsp;Woe&lt;/h1&gt;<br />
&nbsp;&nbsp;&lt;p&nbsp;class=&quot;tagline&quot;&gt;The&nbsp;neverending&nbsp;saga&nbsp;continues...&lt;/p&gt;<br />
&nbsp;&nbsp;<b>&lt;nav&gt;</b><br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;h2&gt;Navigation&lt;/h2&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;ul&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;&lt;a&nbsp;href=&quot;one.html&quot;&gt;Page&nbsp;One&lt;/a&gt;&lt;/li&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;&lt;a&nbsp;href=&quot;two.html&quot;&gt;Page&nbsp;Two&lt;/a&gt;&lt;/li&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;&lt;a&nbsp;href=&quot;three.html&quot;&gt;Page&nbsp;the&nbsp;Third&lt;/a&gt;&lt;/li&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/ul&gt;<br />
&nbsp;&nbsp;<b>&lt;/nav&gt;</b><br />
<b>&lt;/header&gt;</b><br />
<b>&lt;article&gt;</b><br />
&nbsp;&nbsp;&lt;h2&gt;The&nbsp;Stagnant&nbsp;Staircase&lt;/h2&gt;<br />
&nbsp;&nbsp;&lt;p&gt;It was a dark and stormy night. She didn&#x27;t notice the vase by the banister as she walked past it, holding the wilted flowers in stale and murky water. The only thing she knew was that the nightmares had to end, and that they would end tonight...&lt;/p&gt;<br />
<b>&lt;/article&gt;</b><br />
<b>&lt;footer&gt;</b><br />
&nbsp;&nbsp;&lt;p&gt;©2010&nbsp;In&nbsp;Your&nbsp;Nightmares&nbsp;Productions.&lt;/p&gt;<br />
<b>&lt;/footer&gt;</b></code></p>
<p>In the revised HTML5 version, things are much clearer to read. Your eye can readily follow where the beginning and end of the structural blocks are, because they have structural names such as <code>article</code> and <code>footer</code> instead of just generic <code>div</code> elements with nondescript element closings.</p>
<p>The specification defines <code>header</code> as &#8220;a group of introductory or navigational aids.&#8221; This could mean navigation, tag lines, section headings, logos, etc. In this example, we use this element to define the masthead of a page, but it could just as easily be a child of a navigation element or an article too &#8211; if that&#8217;s what the content semantically would require.</p>
<p>The <code>article</code> element represents a defined, distributable piece of content. This might be a press release, a journal article, a blog post, or even a status message such as we&#8217;d see on Twitter. We used it here to begin our piece of pulp fiction. (I&#8217;m sure there&#8217;s more to the story &#8211; perhaps at the next NaNoWriMo I&#8217;ll use that as a germ for an actual story&#8230;)</p>
<h3>Heading groups</h3>
<p>Oh, one more thing about this section that we should address, and here&#8217;s where things get interesting: the tagline. Right now we have a paragraph tag with a class of tagline. And if we&#8217;d like to keep that formatting in place, that&#8217;s fine. However there&#8217;s a new construct in HTML5 that we can leverage, so let&#8217;s take a look at the <code>hgroup</code> element:</p>
<p><code>&lt;hgroup&gt;<br />
&nbsp;&nbsp;&lt;h1&gt;Tales of Woe&lt;/h1&gt;<br />
&nbsp;&nbsp;&lt;h2&gt;The neverending saga continues...&lt;/h2&gt;<br />
&lt;/hgroup&gt;</code></p>
<p>Here what we&#8217;ve done is to change the tagline paragraph into an <code>h2</code> element, and wrap the <code>h1</code> and <code>h2</code> elements inside of an <code>hgroup</code>. The <code>hgroup</code> element is a heading, and can only contain two or more of <code>h1</code> through <code>h6</code>.</p>
<h3>Sectioning off headings</h3>
<p>Furthermore, you can use the <code>section</code> element to help structure your document. In a nutshell, consider that any heading within a <code>section</code> is one level lower than headings of the same face value outside of it. Consider the following markup:</p>
<p><code>&lt;section&gt;<br />
&nbsp;&nbsp;&lt;h1&gt;Homininae&lt;/h1&gt;<br />
&nbsp;&nbsp;&lt;section&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;h1&gt;Gorillini&lt;/h1&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;section&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h1&gt;Gorilla&nbsp;gorilla&lt;/h1&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;section&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h1&gt;Gorilla&nbsp;gorilla&nbsp;gorilla&lt;/h1&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h1&gt;Gorilla&nbsp;gorilla&nbsp;diehli&lt;/h1&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/section&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h1&gt;Gorilla&nbsp;beringei&lt;/h1&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;section&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h1&gt;Gorilla&nbsp;beringei&nbsp;beringei&lt;/h1&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h1&gt;Gorilla&nbsp;beringei&nbsp;graueri&lt;/h1&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/section&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/section&gt;<br />
&nbsp;&nbsp;&lt;/section&gt;<br />
&nbsp;&nbsp;&lt;section&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;h1&gt;Hominini&lt;/h1&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;section&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h1&gt;Pan&lt;/h1&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;section&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h1&gt;Pan&nbsp;traglodytes&lt;/h1&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;section&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h1&gt;Pan&nbsp;troglodytes&nbsp;troglodytes&lt;/h1&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h1&gt;Pan&nbsp;troglodytes&nbsp;verus&lt;/h1&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h1&gt;Pan&nbsp;troglodytes&nbsp;vellerosus&lt;/h1&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h1&gt;Pan&nbsp;troglodytes&nbsp;schweinfurthii&lt;/h1&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/section&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h1&gt;Pan&nbsp;paniscus&lt;/h1&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/section&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/section&gt;<br />
&nbsp;&nbsp;&lt;/section&gt;<br />
&nbsp;&nbsp;&lt;section&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;h1&gt;Homo&lt;/h1&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;section&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h1&gt;Homo&nbsp;sapiens&lt;/h1&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;section&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h1&gt;Homo&nbsp;sapiens&nbsp;sapiens&lt;/h1&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/section&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/section&gt;<br />
&nbsp;&nbsp;&lt;/section&gt;<br />
&lt;/section&gt;</code></p>
<p>These are all <code>h1</code> elements, but structurally the hierarchy is represented as so, due to the nestings of the <code>section</code> elements:</p>
<ul>
<li>Homininae
<ul>
<li>Gorillini
<ul>
<li>Gorilla gorilla
<ul>
<li>Gorilla gorilla gorilla</li>
<li>Gorilla gorilla diehli</li>
</ul>
</li>
<li>Gorilla beringei
<ul>
<li>Gorilla beringei beringei</li>
<li>Gorilla beringei graueri</li>
</ul>
</li>
</ul>
</li>
<li>Hominini
<ul>
<li>Pan
<ul>
<li>Pan traglodytes
<ul>
<li>Pan troglodytes troglodytes</li>
<li>Pan troglodytes verus</li>
<li>Pan troglodytes vellerosus</li>
<li>Pan troglodytes schweinfurthii</li>
</ul>
</li>
<li>Pan paniscus</li>
</ul>
</li>
</ul>
</li>
<li>Homo
<ul>
<li>Homo sapiens
<ul>
<li>Homo sapiens sapiens</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<h3>It&#8217;s turtle headings, all the way down</h3>
<p>In the code, we had all <code>h1</code>s, but the spec requires that the hierarchy is interpreted as shown in this list, and we can clearly see that say homo sapiens sapiens is a subheading of homo sapiens, which is in turn a subheading of homo, then finally homininae. But why does this matter? Well, consider for a moment that the HTML5 specification only allows specific headings of <code>h1</code> through <code>h6</code>. Then consider if we were to extend our taxonomic classification to encompass all mammals. We&#8217;d run out of headings before we got to homininae! In this manner, we can use the <code>h1</code> element ad infinitum within it&#8217;s own <code>section</code> elements, and if we needed we can throw in a little <code>h2</code> through <code>h6</code> if needed. If we run out, just add more <code>section</code>s.</p>
<p>A small caveat, however: Having an endless stream of <code>h1</code>s means today&#8217;s screen readers used by disabled users might have trouble dealing with the hierarchical order of your content, and there is no functional CSS or other construct currently available to work around this problem. If you have accessibility issues to contend with, stick with the traditional usage of <code>h1</code> through <code>h6</code> for now, even if you use <code>heading</code> within.</p>
<h3>Go figure</h3>
<p>The <code>figure</code> and <code>figcaption</code> elements are for inserting and captioning figures in text documents. Before, we didn&#8217;t have an effective way to mark up figure images, and certainly had to come up with creative ways to mark up captions. These elements wrap this problem up nicely.</p>
<p><code>&lt;figure&gt;<br />
&nbsp;&nbsp;&lt;img src=&quot;Viola.jpg&quot;&gt;&lt;/video&gt;<br />
&nbsp;&nbsp;&lt;figcaption&gt;This is a lovely Amati 1710 viola.&lt;/figcaption&gt;<br />
&lt;/figure&gt;</code></p>
<h3>As a side note&#8230;</h3>
<p>The only structural elements I haven&#8217;t mentioned yet is the <code>aside</code> element. The <code>aside</code> element indicates related information. It could be used for what we consider typical &#8220;sidebar&#8221; content in a web page layout, or it could be an aside in a story &#8211; such as a text box titled &#8220;learn more&#8221; in a feature news story or textbook-style article of content. This element may have it&#8217;s own headings, nav, content, and whatnot, and if it is found occurring within an <code>article</code> then it is considered related to that given article of content.</p>
<p>And that just about wraps up an introduction to HTML5 with a brief overview of the core structural and hierarchical elements. As we move forward with <a href="http://www.sanbeiji.com/tag/developingwithhtml5/">this series</a>, we&#8217;ll take a look at the other new elements mentioned above, as well as look at some of the ways HTML5 has refactored existing markup to have new meaning.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.sanbeiji.com/archives/1237/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>First steps with HTML5</title>
		<link>http://www.sanbeiji.com/archives/1214</link>
		<comments>http://www.sanbeiji.com/archives/1214#comments</comments>
		<pubDate>Mon, 08 Nov 2010 02:22:21 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[developingwithhtml5]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[markup]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[webdev]]></category>
		<category><![CDATA[webstandards]]></category>

		<guid isPermaLink="false">http://www.sanbeiji.com/?p=1214</guid>
		<description><![CDATA[As I mentioned in my earlier post, HTML5 means quite a lot more than what we all understood markup to be in the HTML 4/XHTML days. At the core of the HTML5 specification however, markup is still the foundation. Let&#8217;s &#8230; <a href="http://www.sanbeiji.com/archives/1214">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_brick-red" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Fwww.sanbeiji.com%252Farchives%252F1214%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22First%20steps%20with%20HTML5%22%20%7D);"></div>
<p>As I mentioned in my <a href="http://www.sanbeiji.com/archives/1207">earlier post</a>, HTML5 means quite a lot more than what we all understood markup to be in the HTML 4/XHTML days. At the core of the HTML5 specification however, markup is still the foundation. Let&#8217;s take a quick look at some of the differences between HTML5 and it&#8217;s predecessors. But before we get too into this HTML5 series, I should mention that the principal reason I&#8217;m posting my thoughts here on the subject is to learn for myself, and secondly to document a nugget of information or two that might be useful to you all out there. Excellent stuff has been written on this subject. Go read Bruce Lawson and Remy Sharp&#8217;s book <cite><a href="https://www.amazon.com/dp/0321687299?tag=sanbeiji-20&#038;camp=213381&#038;creative=390973&#038;linkCode=as4&#038;creativeASIN=0321687299&#038;adid=1HVYDR4ARQ6GB9MCB0WV&#038;">Introducing HTML5</a></cite>, Mark Pilgrim&#8217;s <cite><a href="https://www.amazon.com/dp/0596806027?tag=sanbeiji-20&#038;camp=213381&#038;creative=390973&#038;linkCode=as4&#038;creativeASIN=0596806027&#038;adid=0MT03EQJ0MXKF4PK8668&#038;">HTML5 Up and Running</a></cite>, and Tantek Çelic&#8217;s <cite><a href="http://www.amazon.com/gp/product/0321719913?ie=UTF8&#038;tag=sanbeiji-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0321719913">HTML5 Now</a></cite>. Go read every one of these books cover to cover — I highly recommend them.</p>
<blockquote><p>It can scarcely be denied that the supreme goal of all theory is to make the irreducible basic elements as simple and as few as possible without having to surrender the adequate representation of a single datum of experience.</p>
<p><em>—Albert Einstein</em></p></blockquote>
<div id="attachment_1215" class="wp-caption alignright" style="width: 310px"><a href="http://www.sanbeiji.com/wp-content/uploads/2010/11/Einstein_and_Tagore_Berlin_14_July_1930.jpg" rel="lightbox[1214]"><img src="http://www.sanbeiji.com/wp-content/uploads/2010/11/Einstein_and_Tagore_Berlin_14_July_1930-300x259.jpg" alt="Einstein and Tagore, Berin, 1930" title="Einstein_and_Tagore_Berlin_14_July_1930" width="300" height="259" class="size-medium wp-image-1215" /></a><p class="wp-caption-text">Physicists with mad hair who most assuredly would have been totally down with HTML5.</p></div>
<p>I will now go through some of the reasoning akin to the way Pilgrim and Lawson follow in constructing the optimal basic HTML5 markup template, with my own commentary, flavor, and style thrown in just so I can acquire it in my head and hopefully help you all along with the reasoning:</p>
<p>The first line of code we see in HTML documents is the doctype. The reason why it is standard practice to use doctypes in markup, as all good web developers already know, is to trigger standards mode in web browsers. All major modern web browsers support this function, and it makes the role of a web developer much simpler to develop a consistent user experience across all platforms. If you&#8217;re familiar with the doctypes of HTML 4 and XHTML 1, you are familiar with how complex they appear.</p>
<p><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"<br />
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;<br />
</code></p>
<p>Not the type of thing one would readily commit to memory at first glance. The HTML5 doctype is significantly shorter:</p>
<p><code>&lt;!DOCTYPE html&gt;<br />
</code></p>
<p>There &#8211; <a href="http://thereifixedit.failblog.org/">fixed it</a>.</p>
<p>With just a little experimentation, it was found that all browsers triggered standards mode with just the above minimal amount of code. So the HTML5 spec was written to codify what was already in existence, in the most compact and simplistic way that works. No long URL. No unmemorable string of voodoo or versioning cluster nonsense. Just the standards mode, please. That&#8217;s all we need &#8211; something simple and to the point.</p>
<p>The next thing you should know about is defining a character set for your document. This is a departure from the straightforwardness of our journey into HTML5 markup, but it is important for addressing a <a title="UTF-7: the case of the missing charset on Google Code" href="http://code.google.com/p/doctype/wiki/ArticleUtf7">security concern</a> where browsers attempt to guess character encodings that could conceal malicious scripts, so let&#8217;s get off on the right foot shall we? First, the old way:</p>
<p><code>&lt;meta http-equiv= "Content-Type" content="text/html; charset=UTF-8"&gt;<br />
</code></p>
<p>Again, not the most memorable code. But then, that&#8217;s why I like HTML5: It fixes things. This is much better:</p>
<p><code>&lt;meta charset="utf-8"&gt;<br />
</code></p>
<p>I should also point out something important here. In HTML5, you don&#8217;t need to place quotation marks around attribute values if there are no spaces. Spaces separate multiple values, and you need those quotes to herd them together and distinguish them from standalone attributes (which we&#8217;ll get into later). So, this would also be perfectly valid:</p>
<p><code>&lt;meta charset=utf-8&gt;<br />
</code></p>
<p>If you&#8217;re compressing a document for speedy delivery over slow networks, such as mobile contexts, then here&#8217;s a place to save a few bytes. But in general, it&#8217;s my personal preference to quote my attribute values for legibility&#8217;s sake.</p>
<p>Another thing you might notice is that this standalone element is not self-closing in the XML sense. You could write it that way, as in:</p>
<p><code>&lt;meta charset="utf-8" /&gt;<br />
</code></p>
<p>That&#8217;s with the trailing slash before the end closing angle bracket, in case you missed it. This would be the way it would be done were our document conforming to XHTML rules. XHTML5 is the XML-conformant variant of HTML5 and is developed as an option to the HTML5 specification. But it is not necessary, unless you really need XML parsing to be enabled. And the good news is, HTML5 allows for SVG and MathML embedding without having to switch to XHTML mode, so for most contexts even at the scientific level, we won&#8217;t need the X tacked on to the front of our HTML5. But please, don&#8217;t let that stop you from self-closing those tags. I myself only recently got out of the habit, after writing HTML5 for the past 10 months or so. It&#8217;s perfectly valid either way.</p>
<p>The rest of your basic HTML5 document at this point will look very familiar, with just a few things to point out. The most notable difference will be the opening HTML tag. Usually we&#8217;d just open up our markup tree with this:</p>
<p><code>&lt;html&gt;<br />
</code></p>
<p>However, if we were pulling out all the XML stops and such, we would be defining a namespace and a language, as so:</p>
<p><code>&lt;html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"&gt;<br />
</code></p>
<p>In HTML5, it is certainly not necessary to define a namespace (the xmlns part) because that much is assumed. That leaves us with the language declaration, in the form of the lang attribute. Lang attributes are specified according to <a title="IETF BCP 47: Tags for Identifying Languages" href="http://www.ietf.org/rfc/bcp/bcp47.txt">IETF BCP47</a>, and there&#8217;s a <a title="MSDN: Language Codes" href="http://msdn.microsoft.com/en-us/library/ms533052(VS.85).aspx">practical list of these codes</a> that may be used on MSDN. A lang attribute is used by search engines to understand the content meaning better and categorize the results. It is used by speech synthesizers to produce the correct pronunciation of words with similar spellings across languages. It is used by browsers for producing the correct hyphenation, spelling correction, and so on, even across regional dialects. A lang attribute specifies the language of the contents of the given element, which means you may specify several languages on a given document.</p>
<p>Do use the lang attribute. Even better &#8211; use it regionally. I would specify lang=&#8221;en-us&#8221; (English &#8211; U.S.) for most of my web work, but on occasion I&#8217;ll dip into Traditional Chinese for my language studies, with specific vocabulary rules for Taiwan, in which case I&#8217;d use lang=&#8221;zh-tw&#8221; (Chinese, or &#8220;zhongwen&#8221; &#8211; Taiwan).</p>
<p>I&#8217;m fascinated by language processing and character sets in computing, so forgive my overly-thorough description of the situation back there. The point is, in HTML5, we can shorten this information on the opening HTML element to this by removing the namespace and the xml:lang attributes, and including the addition of my regional preference:</p>
<p><code>&lt;html lang="en-us"&gt;<br />
</code></p>
<p>There, that&#8217;s a <em>gooood</em> HTML element. For other elements in your document, such as perhaps LI or P, you might specify additional languages as needed.</p>
<p>Bruce Lawson has a <a title="Bruce Lawson’s  personal site : A Minimal HTML5 Document" href="http://www.brucelawson.co.uk/2010/a-minimal-html5-document/">nice, clear writeup</a> of what he considers to be the minimal HTML5 document framework. I agree with this markup template, with my own minor stylistic modifications presented below:</p>
<p><code>&lt;!DOCTYPE html&gt;<br />
&lt;html lang="en-us"&gt;<br />
&lt;head&gt;<br />
&nbsp;&nbsp;&lt;meta charset="utf-8"&gt;<br />
&nbsp;&nbsp;&lt;title&gt;My Page Title&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&nbsp;&nbsp;&lt;p&gt;My awesome web page.&lt;/p&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
</code></p>
<p>The rest is pretty straightforward, right? We have the overall wrapping HTML element, a HEAD, a BODY, our charset definition, our lang attribute set to Amurikun, well-formed tag organization, a title attribute, and some content. That&#8217;s it &#8211; not too different from our past experiences with HTML4 and XHTML, but arguably much simpler. You now can fill in the rest of your markup as needed as if it were HTML 4.01, and it&#8217;ll work in all modern browsers. That&#8217;s right, it&#8217;s OK to get started with this much right away. But if we stopped there, that would be missing the point of the new semantic conveniences of HTML5! So in the next post we will explore those constructs in a little more detail and talk about how these new constructs will save you time and make more sense for web development in the long run.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.sanbeiji.com/archives/1214/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced

Served from: www.sanbeiji.com @ 2012-02-12 03:51:57 -->
