HTML 5 and CSS 3: The Techniques You'll Soon be Using

HTML 5 and CSS 3: The Techniques You’ll Soon Be Using

Tutorial Details
  • Technology: CSS3, HTML 5
  • Difficulty: Intermediate
  • Completion Time: 1-2 hours

Final Product What You'll Be Creating

In this tutorial, we are going to build a blog page using next-generation techniques from HTML 5 and CSS 3. The tutorial aims to demonstrate how we will be building websites when the specifications are finalized and the browser vendors have implemented them. If you already know HTML and CSS, it should be easy to follow along.


1. HTML 5

HTML 5 is the next major version of HTML. It introduces a bunch of new elements that will make our pages more semantic. This will make it a lot easier for search engines and screenreaders to navigate our pages, and improve the web experience for everyone. In addition, HTML 5 will also include fancy APIs for drawing graphics on screen, storing data offline, dragging and dropping, and a lot more. Let’s get started marking up the blog page.


2. Basic Structure

Before we begin marking up the page we should get the overall structure straight:

Diagram of basic structure

In HTML 5 there are specific tags meant for marking up the header, navigation, sidebar and footer. First, take a look at the markup and I’ll explain afterwards:

<!doctype html>
<html>
<head>
	<title>Page title</title>
</head>
<body>
	<header>
		<h1>Page title</h1>
	</header>
	<nav>
		<!-- Navigation -->
	</nav>
	<section id="intro">
		<!-- Introduction -->
	</section>
	<section>
		<!-- Main content area -->
	</section>
	<aside>
		<!-- Sidebar -->
	</aside>
	<footer>
		<!-- Footer -->
	</footer>

</body>
</html>

It still looks like HTML markup, but there are a few things to note:

  • In HTML 5, there is only one doctype. It is declared in the beginning of the page by <!doctype html>. It simply tells the browser that it’s dealing with an HTML-document.
  • The new tag header is wrapped around introductory elements, such as the page title or a logo. It could also contain a table of contents or a search form. Every header typically contains a heading tag from <h1> to <h6>. In this case the header is used to introduce the whole page, but we’ll use it to introduce a section of the page a little later.
  • The nav-tag is used to contain navigational elements, such as the main navigation on a site or more specialized navigation like next/previous-links.
  • The section-tag is used to denote a section in the document. It can contain all kinds of markup and multiple sections can be nested inside each other.
  • aside is used to wrap around content related to the main content of the page that could still stand on it’s own and make sense. In this case we’re using it for the sidebar.
  • The footer-tag should contain additional information about the main content, such as info about who wrote it, copyright information, links to related documents and so on.

Instead of using divs to contain different sections of the page we are now using appropriate, semantic tags. They will make it a lot easier for search engines and screen readers to figure out what’s what in a page.


3. Marking Up the Navigation

The navigation is marked up exactly like we would do it in HTML 4 or XHTML, using an unordered list. The key is that this list is placed inside the nav-tags.

<nav>
	<ul>
		<li><a href="#">Blog</a></li>
		<li><a href="#">About</a></li>
		<li><a href="#">Archives</a></li>
		<li><a href="#">Contact</a></li>
		<li class="subscribe"><a href="#">Subscribe via. RSS</a></li>
	</ul>
</nav>

4. Marking Up the Introduction

We have already defined a new section in the document using the section tag. Now we just need some content.

<section id="intro">
	<header>
		<h2>Do you love flowers as much as we do?</h2>
	</header>
	<p>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.</p>
</section>

We add an id to the section tag so we can identify it later when styling. We use the header tag to wrap around the introductory h2 element. In addition to describing a whole document, the header-tag should also be used to describe individual sections.


5. Marking Up the Main Content Area

Our main content area consists of three sections: the blog post, the comments and the comment form. Using our knowledge about the new structural tags in HTML 5, it should be easy to mark it up.

Marking up the Blog Post

Go through the markup and I’ll explain the new elements afterwards.

<section>
	<article class="blogPost">
		<header>
			<h2>This is the title of a blog post</h2>
			<p>Posted on <time datetime="2009-06-29T23:31:45+01:00">June 29th 2009</time> by <a href="#">Mads Kjaer</a> - <a href="#comments">3 comments</a></p>
		</header>
		<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin euismod tellus eu orci imperdiet nec rutrum lacus blandit. Cras enim nibh, sodales ultricies elementum vel, fermentum id tellus. Proin metus odio, ultricies eu pharetra dictum, laoreet id odio...</p>
	</article>
</section>

We start a new section and wrap the whole blog post in an article-tag. The article tag is used to denote an independent entry in a blog, discussion, encyclopedia, etc. and is ideal to use here. Since we are viewing the details of a single post we only have one article, but on the front page of the blog we would wrap each post in an article-tag.

The header element is used to present the header and metadata about the blog post. We tell the user when the post was written, who wrote it and how many comments it has. Note that the timestamp is wrapped in a

Diagram describing use of the datetime HTML attribute
  1. The year followed by a figure dash (a minus sign to you non-typography nerds)
  2. The month followed by a figure dash
  3. The date
  4. A capital T to denote that we are going to specify the local time
  5. The local time in the format hh:mm:ss
  6. The time zone relative to GMT. I’m in Denmark which is 1 hour after GMT, so I write +01. If you were in Colorado you would be 7 hours behind GMT, and you would write -07.

Marking up the Comments

Marking up the comments is pretty straight-forward. No new tags or attributes are used.

<section id="comments">
	<header>
		<h3>Comments</h3>
	</header>
	<article>
		<header>
			<a href="#">George Washington</a> on <time datetime="2009-06-29T23:35:20+01:00">June 29th 2009 at 23:35</time>
		</header>
		<p>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.</p>
	</article>
	<article>
		<header>
			<a href="#">Benjamin Franklin</a> on <time datetime="2009-06-29T23:40:09+01:00">June 29th 2009 at 23:40</time>
		</header>
		<p>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.</p>
	</article>
</section>

Marking up the Comment Form

Several enhancements to forms have been introduced in HTML 5. You longer have to do client-side validation of required fields, emails, etc. The browser takes care of this for you.

<form action="#" method="post">
	<h3>Post a comment</h3>
	<p>
		<label for="name">Name</label>
		<input name="name" id="name" type="text" required />
	</p>
	<p>
		<label for="email">E-mail</label>
		<input name="email" id="email" type="email" required />
	</p>
	<p>
		<label for="website">Website</label>
		<input name="website" id="website" type="url" />
	</p>
	<p>
		<label for="comment">Comment</label>
		<textarea name="comment" id="comment" required></textarea>
	</p>
	<p><input type="submit" value="Post comment" /></p>
</form>

There are new two new types of inputs, email and url. Email specifies that the user should enter a valid E-mail, and url that the user should enter a valid website address. If you write required as an attribute, the user cannot submit an empty field. “Required” is a boolean attribute, new to HTML 5. It just means that the attribute is to be declared without a value.

Marking up the Sidebar and Footer

The markup of the sidebar and footer is extremely simple. A few sections with some content inside the appropriate aside- and footer-tags.

You can view the final, unstyled markup here. Now for the styling.


6. Styling with CSS 3

CSS 3 builds upon the principles about styles, selectors and the cascade that we know so well from earlier versions of CSS. It adds loads of new features, including new selectors, pseudo-classes and properties. Using these new features it becomes a lot easier to set up your layout. Let’s dive in.

Basic Setup

To start off with we are going to define some basic rules concerning typography, background color of the page, etc. You’ll recognize all of this from CSS 2.1

/* Makeshift CSS Reset */
{
	margin: 0;
	padding: 0;
}

/* Tell the browser to render HTML 5 elements as block */
header, footer, aside, nav, article {
	display: block;
}

body {
	margin: 0 auto;
	width: 940px;
	font: 13px/22px Helvetica, Arial, sans-serif;
	background: #f0f0f0;
}

h2 {
	font-size: 28px;
	line-height: 44px;
	padding: 22px 0;
}

h3 {
	font-size: 18px;
	line-height: 22px;
	padding: 11px 0;
}

p {
	padding-bottom: 22px;
}

First we reset margin- and padding-styles with a simple rule. In a production environment I would use a more complete CSS Reset such as Eric Meyer’s (for CSS 2.1) but for the scope of the tutorial this will do.

We then tell the browser to render all the new HTML 5 elements as block. The browsers are fine with elements they don’t recognize (this is why HTML 5 is somewhat backwards compatible), but they don’t know how those elements should be rendered by default. We have to tell them this until the standard is implemented across the board.

Also note how I’ve chosen to size the fonts in pixels instead of ems or %. This is to maintain the progressive nature of the tutorial. When the major browsers one day are completely finished implementing HTML 5 and CSS 3 we will all have access to page zooming instead of just text resizing. This eliminates the need to define sizes in relative units, as the browser will scale the page anyway.

See what the page looks like with the basic styling applied. Now we can move on to styling the rest of the page. No additional styles are required for the header, so we’ll go straight to the navigation.


7. Styling the Navigation

It is important to note that the width of the body has been defined as 940px and that it has been centered. Our navigation bar needs to span the whole width of the window, so we’ll have to apply some additional styles:

nav {
	position: absolute;
	left: 0;
	width: 100%;
	background: url("nav_background");
}

We position the nav-element absolutely, align it to the left of the window and make it span the whole width. We’ll center the nested list to display it within the boundaries of the layout:

nav ul {
	margin: 0 auto;
	width: 940px;
	list-style: none;
}

Now we’ll define some additional styles to make the navigation items look prettier and align them to the grid the layout is based on. I’ve also included a style for highlighting the page the user is on, and some custom styling for the subscription-link.

nav ul li {
	float: left;
}

	nav ul li a {
		display: block;
		margin-right: 20px;
		width: 140px;
		font-size: 14px;
		line-height: 44px;
		text-align: center;
		text-decoration: none;
		color: #777;
	}

		nav ul li a:hover {
			color: #fff;
		}

		nav ul li.selected a {
			color: #fff;
		}

		nav ul li.subscribe a {
			margin-left: 22px;
			padding-left: 33px;
			text-align: left;
			background: url("rss.png") left center no-repeat;
		}

8. Styling the Introduction

The markup for the introduction is pretty simple: A section with a heading and a paragraph of text. However, we’ll use some new CSS 3 tricks to make it look more appealing.

#intro {
	margin-top: 66px;
	padding: 44px;
	background: #467612 url("intro_background.png") repeat-x;
	background-size: 100%;
	border-radius: 22px;
}

We are using two new properties. The first one is background-size, which allows you to scale the background-image. In our case, we scale it to 100% on both axes. If the box expands as we add more content to it, the gradient background will scale as well. This is something that was not possible in CSS 2.1 without non-semantic markup and miscellaneous browser issues.

The second new property is border-radius, which applies rounded corners to the element. The radius of our rounded corners are 22px in every corner. You could specify different values for each corner or choose to only round individual corners.

Unfortunately, neither of the properties are fully implemented into the major browsers. However, we can get some support by using vendor-specific attributes. Background-size is supported by newer versions of Safari, Opera and Konqueror. Border-radius is supported by newer versions of Safari and Firefox.

#intro {
	...
	/* Background-size not implemented yet */
	-webkit-background-size: 100%;
	-o-background-size: 100%;
	-khtml-background-size: 100%;

	/* Border-radius not implemented yet */
 	-moz-border-radius: 22px;
	-webkit-border-radius: 22px;
}

Since we have a background-color defined, there will be no major problems in browsers that don’t support background-size, such as Firefox. Now we just need to style the heading and the text.

#intro h2, #intro p {
	width: 336px;
}

#intro h2 {
	padding: 0 0 22px 0;
	font-weight: normal
	color: #fff;
}

#intro p {
	padding: 0;
	color: #d9f499;
}

The flower image can be added easily by giving #intro a second background image, something that CSS 3 supports.

#intro {
	...
	background: #467612 url("intro_background.png") top left (287px 100%) repeat-x,
			url("intro_flower.png") top right (653px 100%) no-repeat;
	...
}

We give the two background images explicit dimensions to ensure that they don’t overlap, and we’re set. Note the shorthand notation of background-size.

Unfortunately, no browser reliably supports this yet, so we’ll have to do it the old-fashioned way: by including an inline image and positioning it using CSS. See the final example to see how it was done.


9. Styling the Content Area and Sidebar

The content area and sidebar are going to be aligned beside each other. Traditionally you would do this by using floats, but in CSS 3 we are going to use tables!

“What?! Tables?” you might ask and look confused. You probably learned years ago that using tables for web layout is a big no-no, and it still is. You should never use the table-element to mark up a layout. However, in CSS 3 we can make elements behave like tables without it ever showing in the markup! To start off with, we’re going to need some divs to group the sections in a little more logical manner.

<div id="content">
	<div id="mainContent">
		<section>
			<!-- Blog post -->
		</section>
		<section id="comments">
			<!-- Comments -->
		</section>
		<form>
			<!-- Comment form -->
		</form>
	</div>
	<aside>
		<!-- Sidebar -->
	</aside>
</div>

Everything still makes sense semantically, but now we can style it. We want the #content div to behave like a table, with #mainContent and aside as table-cells. With CSS 3, this is very easy:

#content {
	display: table;
}

	#mainContent {
		display: table-cell;
		width: 620px;
		padding-right: 22px;
	}

	aside {
		display: table-cell;
		width: 300px;
	}

That’s all! No more floating, faux column background images, clearing or collapsing margins. We’ve made the elements behave like a table, and this makes it much easier for us to do layout.


10. Styling the Blog Post

The styling of the post header is rather trivial so I’ll skip to the fun part: the multi-column layout.

Multiple columns

Multiple columns of text was previously impossible without manually splitting the text, but with CSS 3 it’s a piece of cake, although we have to add a div around the multiple paragraphs for this to work with current browsers.

<div>
	<p>Lorem ipsum dolor sit amet...</p>
	<p>Pellentesque ut sapien arcu...</p>
	<p>Vivamus vitae nulla dolor...</p>
	...
</div>

Now we can add two simple properties and call it a day.

.blogPost div {
	column-count: 2;
	column-gap: 22px;
}

We want 2 columns and a gap of 22px between the columns. The additional div is needed because there is currently no supported way of making an element span more than one column. In the future, however, you’ll be able to specify the column-span property, and we could just write:

.blogPost {
	column-count: 2;
	column-gap: 22px;
}

	.blogPost header {
		column-span: all;
	}

Of course the column-count and column-gap properties are only supported by some browsers, Safari and Firefox. We have to use the vendor-specific properties for now.

.blogPost div {
	/* Column-count not implemented yet */
	-moz-column-count: 2;
	-webkit-column-count: 2;

	/* Column-gap not implemented yet */
	-moz-column-gap: 22px;
	-webkit-column-gap: 22px;
}

Box shadow

If you look closely at the image in the blog post you’ll see a drop-shadow. We are able to generate this using CSS 3 and the box-shadow property.

.blogPost img {
	margin: 22px 0;
	box-shadow: 3px 3px 7px #777;
}
Illustration describing how the browsers render the box-shadow CSS property

The first “3px” tells the browser where we want the shadow to stop horizontally. The second “3px” tells it where we want the shadow to stop vertically. The last “7px” is how blurred the border should be. If you set it to 0 it will be completely solid. Last but not least we define the base color of the shadow. This color is of course faded, depending on how much you blur the shadow.

It probably comes as no surprise that this property is not implemented in all browsers yet. In fact, it only works in Safari, and you have to use the vendor-specific property.

.blogPost img {
	margin: 22px 0;
	-webkit-box-shadow: 3px 3px 7px #777;
}

11. Zebra-striping the Comments

Zebra-striping, or highlighting every second element in a series, has traditionally involved selecting all the elements via javascript, then looping through them and highlighting all the odd elements. CSS 3 introduces the pseudo-class “nth-child”, which makes it ridiculously simple to do this without javascript. We’ll use it to zebra-stripe the comments.

section#comments article:nth-child(2n+1) {
	padding: 21px;
	background: #E3E3E3;
	border: 1px solid #d7d7d7;

	/* Border-radius not implemented yet */
	-moz-border-radius: 11px;
	-webkit-border-radius: 11px;
}

The weird value “2n+1″ is actually pretty simple if you understand what it stands for:

  • 2n selects every second item. If you wrote 3n it would select every third item, 4n every fourth item, and so on.
  • The +1 tells the browser to start at element 1. If you are familiar with programming you probably know that all arrays start at 0, and this is also true here. This means that element 1 is actually the second element in the series.

Alternatively, you could simply write:

section#comments article:nth-child(odd) { ... }

Since the standard includes the two most used values as shorthand, odd and even. The rest of the comment styling should be simple to understand with your new knowledge.

Styling the Comment Form, Footer and Sidebar

A couple of CSS 3 techniques are reused in the styling of the comment form, footer and sidebar. In the comment form and the footer I’ve used the same type of table layout technique used in the main layout. In the sidebar border-radius is used to add rounded corners to the different sections.


12. The Final Design

See the final design with all styling applied.

Compatibility

The page renders correctly in Safari 4 and newer webkit-based browsers, as it is the only rendering engine that supports all of the CSS 3 techniques we have used. Firefox 3 has some problems applying rounded corners to our flower image and it doesn’t support background-size, but besides that the layout works. I’ve chosen to ignore Internet Explorer as it requires a bit of hacking to get HTML 5 to work. You could also define some more rules and get everything working across major browsers, but all of this is outside the scope of the tutorial.

Conclusion

When HTML 5 and CSS 3 are one day implemented in all browsers it will be a lot easier to build websites. We’ll finally be able to stop using floats for layout (which they were never meant to be used for), and we will spend considerably less time writing javascript to scale our background images or zebra-stripe our tables. Hopefully we will use all this extra time to study some long-neglected areas of web design, like front end optimization and proper information architecture.


Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • Mohammad Atif

    this one is really useful. Thanks

    • bill

      Not really. I applaud the intent but this is just a case of putting the cart before the horse. As the author points out himself, HTML5 and CSS3 aren’t ready for prime time and the overwhelming majority of browsers don’t support them. While it’s nice to get a look into what’s to come I don’t think that anyone is going to start creating sites that are HTML5 valid just yet.

      • http://www.complimedia.com Montana Flynn

        Not very useful, but a great tutorial none the less. I believe it is good practice to use progressive techniques in my projects, it makes it easier to adapt when the time comes and makes your portfolio shine that much more for clients who appreciate web design and semantic markup.

        I used a lot of CSS 3 for my blog, which still works in all browsers http://blog.complimedia.com

      • http://www.brianswebdesign.com Brian Temecula

        Also, the fact that there is nothing that can’t be done with our current CSS/XHTML technology just creates more work for us, or something new to learn at best.

      • http://joshminnich.com Josh Minnich

        I agree that HTML 5 and CSS 3 are going to be great. But if your doing work for anyone but yourself, you might as well ignore all the hype. I’m guessing there won’t be global HTML 5 and CSS 3 support for at least another 5 years. Great article non-the-less.

      • http://jashsayani.com Jash Sayani

        @bill: I am almost done with my HTML 5 Portfolio and its great!

        Though, I agree that most will start using HTML 5 after some time….

      • http://www.ifadey.com iFadey

        We must not remain close minded. We must accept and keep learning new technologies even before its proper release to become a great developer.

      • http://www.sonataforum.net Robert W

        I came here to learn more about HTML 5 and CSS 3 because I intend to solely use PHP, MySQL, HTML5/XHTML2/XML and CSS3 for all of my many web sites. (I am intentionally omitting Flash, JavaScript and any Transitional versions of HTML/XHTML from that brief list.)

        I totally agree with the author’s last paragraph about the need to study those areas of web design that have been long-neglected, and that HTML 5 and CSS 3 are making life so much easier for me now!

    • awake

      You might also find this useful…

      http://www.zeldman.com/2009/07/13/html-5-nav-ambiguity-resolved/#comment-44699

      it’s a heated discussion on HTML 5

  • http://stacey.hoganau.com Stacey

    Nice tutorial, but it seems as though you aren’t supposed to use header, section or h tags inside a footer tag

    http://html5.validator.nu/?doc=http%3A%2F%2Fnettuts.s3.amazonaws.com%2F373_html5%2Ffinal%2Findex.html

    http://dev.w3.org/html5/spec/Overview.html#the-footer-element

  • http://www.developnew.com Developnew

    Is it possible, I don’t think..

    Demo is working in FF3, Chroma

    But its not working in ie6 and ie7

    ????? Should we use it.

    • http://twitter.com/mads Mads Kjaer
      Author

      Read the section about compatibility. This tutorial was designed to demonstrate how one can use HTML 5 and CSS 3 techniques when they are fully implemented. IE6 and IE7 don’t support either. Luckily there is some backwards compatibility, and you could serve them alternate stylesheets and whatnot, but on the bottom line you’d have to write twice the amount of code to get it working in IE.

    • http://webpixl.com Joe

      ITS NOT WORKING IN IE8!

      • noski

        Fuck IE

    • Adrie K

      Microsoft has never been leading in internet developments, and the next version of IE will probably follow a non-compatible deviation of html 5 to cripple other browser. Why should we obey microsoft?
      HTML5 pages render reasonable wel in IE so please, please, please, ignore the great leaders from redmont and *stick to standards* (even if not adapted by all)

    • santosh

      You can use some JS hack to make HTML5 and CSS3 work in IE6/7. I suggest below JS lib :

      HTML5 support in IE6/7 : HTML-shiv ( http://code.google.com/p/html5shiv/ )
      support to some properties of CSS3 in IE6/7 : IE-7-js ( http://code.google.com/p/ie7-js/ )

      Hope this will be helpful.

  • http://themeforest.net/user/kiziel?ref=kiziel kiziel

    Nice tutorial, i like the new html structure. But I dont think we’ll soon be using it. Not yet :[ .

    • shoves

      Nice tutorial….. like the fact it works well in FF but unfortunately we have to design for the “other” browsers as well.

      Good to get up to speed with this markup in the meantime until it comes into full swing.

      Thanx for the tutorial btw!

  • Vincent

    The current mainstream Html 4.01 is drafted in 1999. Html5 is a big improvement, but it is not here quick enough. Not to mention even in Html5 there are still some huge semantic limits of how we freely write documents – a meaningful, content-behavior-presentation separated future of web still has a long way to go.

    Sorry, just a regular depressed Tuesday in the office.

  • http://creamscoop.com/ Carlos P

    Nice tutorial. Amazing quality as always!
    I can’t wait till we can finally use HTML5/CSS3.

  • http://thatryan.com Ryan

    Nice write up, very helpful for seeing the future. Do you think it is time to start making websites in the fashion now?

  • http://www.chezchris.de chris

    Was really looking forward to a tut like this :)

    • careculp

      cabrón que sos bien feo

  • http://h4kme.info/ Stefan

    Nice tutorial man, i totally agree with new HTML 5 Structure, but because browsers didn’t implemented HTML 5 then HTML 6 could be blue-printed so maybe, but i say maybe HTML 6 would be better to implement in browsers(i don’t have idea how HTML 6 should look in a way of syntax). Thanks

  • http://blog.insicdesigns.com insic

    How soon is soon? :) Developers and designers is now coping up HTML5 and CSS3 but most browsers dont support it yet. How about the F! IE? Is there another hack/trick so that i will render html5 and css3?

    Nice tut by the way.

    • http://blog.insicdesigns.com insic

      typo: Is there another hack/trick so that it will render html5 and css3?

      • http://twitter.com/mads Mads Kjaer
        Author

        You can use both HTML 5 and CSS 3 right now if you wanted! There are multiple sites already implementing them (see http://html5gallery.com/)

        IE will render the new HTML 5 elements covered in this article if you specify display:block; in your stylesheet. Of course there is no direct support for and such tags, but you can serve alternate content to those browsers.

        Many CSS-properties degrade gracefully (don’t break browsers that don’t support them). This is for example true for the border-radius property. If the browser doesn’t support border-radius, it will just render the corners as squares. You layout will not break, it will just look slightly worse.

    • Rajan

      This is Very nice article. Its Html5 and css3 samples or very fine. but ie8 not support some selectors like radius.

  • http://www.paulchater.co.uk Paul Chater

    All I can say is bloomin’ awseome. This’ll definitely help me out when CSS3 / HTML5 gets implemented PROPERLY across all browsers. Hopefully with no hacking required.

    I’ve noticed how IE8 is becoming a much better browser render wise too. Sure it hasn’t got CSS3 yet, but rendering actual layouts requires far less hacking than it did before.

  • Harro

    My Firefox 3.5 on the mac seems to have some issues with the introduction :(

    The images aren’t aligned properly.

    The rest seems fine :D

    • http://andrewcrocker.com Andrew

      Nah, it looks more like a color profile thing to me… It’s substantially brighter in Firefox than in Safari.

      They may need another tutorial on getting color spaces/profiles playing nice on all of these new browsers that support it now.

  • http://www.linkedin.com/in/boyeoomens Boye

    @insic: to answer your question concerning HTML5 rendering in IE: yes there is…take a look at Remy Sharp’s blog for more detailed info: http://remysharp.com/2009/01/07/html5-enabling-script/

    Cheers

  • sam

    A pity we can’t really start using this at least for another 2-3 years

    • Chris Simpson

      yep, at least :(

    • Rob

      Hmm. OK. I’ll stop now then. And take down my two sites that do.

    • http://www.quizzpot.com crysfel

      … or maybe more :S

    • Duluoz

      There’s no reason you can’t use them both now with the understanding that new HTML 5 elements and CSS3 properties will not be backwards compatible.

    • Lane

      Depends on what you’re building. I have the flexibility to build our internal apps using the latest stuff, because I can force my coworkers to upgrade their browsers (which they usually do, without me asking).

  • http://www.apoorvvaidya.com Apoorv Vaidya

    Great tutorial, I should start learning this stuff myself. Do you recommend any specific resources, or should I just google it? :)

  • http://www.hongmop.cn hongmop

    Great tutorial,let me try!

  • http://cssfairy.com CSSfairy

    Really great article! Thanks.
    Btw the link to the authors twitter account is broken.

  • http://www.polarfoundation.org Jérôme Coupé

    ahem …

    should not be used blindly to mark a sidebar.

    http://html5doctor.com/understanding-aside/

    Styling zones with display:table; and display:table-cell; is not really the way to go IMHO. This technique is source order dependent and you also loose the ability to position items absolutely within relative blocks.

    http://alastairc.ac/2006/06/css-tables-verses-layout-tables/
    http://www.digital-web.com/articles/everything_you_know_about_CSS_Is_wrong/comments/

  • http://h4kme.info/ Stefan

    I wouldn’t be so pessimistic, the web that we know will be history when P2P browsers start working many extensions and engines will come with that, to simplify there will be no firefox , ie, opera etc but only one universal browser without need to make compatibility css files that is the future.

    • Steve

      +1

    • Nick

      Agreed, that will be the future, but there that is a long long way off. For now people like the fact that there are different browsers; people with different tastes use different browsers. At least in the non developer community anyway.
      In the developer / designer community i think there is more of an ideal for one browser to cut times that we spend with IE hacks and such, developing for one browser would be the simplest way to ensure a look that isn’t browser dependant :)

    • Duluoz

      Will never happen. Theres no incentive to consolidate when you have such lucrative business models as the various vendors have now.

      • http://h4kme.info/ Stefan

        I know it will be hard way to come to this, but eventually after 20 years it could happened.

  • http://www.cobuspotgieter.com Niklas

    Interesting article. I really don’t like the article tag, I understand the meaning of it but to me “record” or “entry” or even “post” would be a better name than article.

    The first example with an actual article in the tutorial is very nice but when using the article tag in the comments section just confuses me. All the other tags makes so much more sense (header, footer, nav etc). I’m not saying the tutorial confuses me, the article tag is. Maybe just me… :)

    • http://www.adolpi.com/ Benjamin

      I read it like this, if that helps :-)

      “an individual object, member, or portion of a class; an item or particular: an article of food; articles of clothing.”

      Courtesy dictionary.com

  • http://www.pixelsoul.com pixelsoul

    I like the structure of HTML5. So simple any moron can write mark up now. I remember when knowing HTML was so something special lol.

    I don’t think that we will be able to expect the majority of browsers out there to support HTML5 anytime soon, which makes me sad.

  • http://www.freshclickmedia.com Shane

    Interesting tutorial. I’m looking forward to working with HTML5.

  • http://www.imblog.info Muhammad Adnan

    when we can use HTML5 in our projects ? when browsers will support ?

    • http://twitter.com/mads Mads Kjaer
      Author

      Newer browsers, such as Safari 4 and Firefox 3.5, are already supporting HTML 5. You can get older browsers to render the structure tags (header, section, footer and so on) by specifying display:block; in your stylesheet, as covered in the tutorial.

  • http://www.totalmedial.de Volly

    The “required” in the input-fields confuses me – that’s no valid XML.
    Is the fall-back to XML-Syntax required=”required “?

    • http://mdm-adph.blogspot.com mdmadph

      But isn’t that why this is HTML and not XHTML?

  • Ricantails

    Great Tutorial! i’m looking forward to see more HTML5 tutorial, expecially something with the “eventsource” tag, witch seems to be really interesting in future development

  • http://111downloads.com guru

    you css tags not working html . what can i do

  • http://www.weebee.be Falco
    • http://www.tyssendesign.com.au John Faulds

      That’s a spurious argument. CSS2.1 is still only a candidate recommendation with the W3C but is mostly supported by all the major browsers.

      HTML5 might not reach final recommendation until 2022 but browsers are implementing parts of the spec already and as Mads Kjaer pointed out, there’s lots of examples of sites already using HTML5 in the HTML5 Gallery.

  • http://www.adolpi.com/ Benjamin

    This strikes me as a little daft – don’t get me wrong, the article is great and I’m looking forward to designing in HTML 5 & CSS 3, but it’s just going to be another headache :-(

    Think about it, we’re still having to design for IE6, how the hell long is it going to be before /everyone/ is able to render these new technologies and ‘backward-compatiblity’ can the die the swift death it deserves?

    Until that day developers have to account for an ever increasing number of ‘half-way’ browsers with various levels of support for these fancy features; if these are suppose to be time saving (dynamic rounded corners, for example) they’re not doign a great job :-P

  • Mike

    Looks like you haven’t quite got the hang of it yet. 9 errors on the page, surely validation is still important.

    • http://www.markrushworth.com mark rushworth

      hahahaha

    • http://twitter.com/mads Mads Kjaer
      Author

      Since the specification is not finalized I didn’t think it would make sense to validate just yet, but here is a short explanation of the errors the validator outputs:

      1. No character encoding. This was left out to keep the HTML document very basic, but it can be fixed by simply inserting a META-tag describing the character encoding, like you would in previous versions of HTML.

      2. It seems there cannot be sections within a footer-tag. From the spec (editor’s draft):

      “The footer element is inappropriate for containing entire sections. For appendices, indexes, long colophons, verbose license agreements, and other such content which needs sectioning with headings and so forth, regular section elements should be used, not a footer.”

      I’m pretty sure I read somewhere that section-tags could be nested within most block-level elements, but the spec makes sense.

  • Amir

    Nice tutorial, but you shouldn’t use aside as a sidebar element as we know it today.

    should only be used to visually separate text from the main content.

    • http://www.markrushworth.com mark rushworth

      html used to ‘visually separate’ eh? what about the semantic web?

    • http://www.tyssendesign.com.au John Faulds

      That’s right and you can read up more on that issue at http://html5doctor.com/

    • http://benbankson.com Ben

      Is there a better solution then for marking up a sidebar? Using another section tag just seems so boring! It just seems to me that something as common as a sidebar should have it’s own markup the same way that header, footer, and nav do.

      Great article Mads! Definitely gonna play around with this now :)

      • http://www.tyssendesign.com.au John Faulds

        Doesn’t look like it. I’m feeling a bit the same way too.

      • Rob

        My understanding of “Aside” is its more for related content to the article. In typical website layouts, you have a content area and a sidebar with generally unrelated items, ads, login/admin, blogrolls, etc.

        Aside is for content related to the article, such as a photo, related links, associated audio, maps etc. I see Aside as an floated element within the article tags:

        So my markup would be:

        headline

        related content

        body

        comment code, extras like “Tweet this”

        ads, blah

        footer stuff

        As for its usability today, there is some javascript and CSS defaults to make the elements stylable in older browsers. I’m building my own WP theme that will be HTML5/CSS3 and we will see how it goes.

  • Snorri-Css

    O WOW! how nice it would be to use HTML5 / CSS3 in our work :D
    people are asking how long until we can start using it.
    not for a LONG TIME! i say
    as long as we have IE6 that will never DIE and after he is dead we have IE7 and 8 that not support this but we can probably make it work with some tweaks and workarounds but full support and no HACKS! in all browsers i am not seeing that happen any time soon.
    are you ?

  • John

    How soon? Anything between 4 to 12 years and while you must be thinking “wow thats a long time but i’m sure theres a reason for that” i’ll bet you anything that in 12 years after all this work we’ll still be banging our heads trying to make stuff cross-browser compatible and fixing IE bugs :)

  • http://web.splesh.net Stefnao

    This doesn’t want to be a criticism, but if you try to validate the demo at http://validator.w3.org/#validate_by_uri+with_options
    it gives back 9 errors, is the page wrong or it’s the validator that is still in experimental?

    Great tut anyway, i found it very interesting to start working with html5

  • http://web.splesh.net Stefano

    Oh i didn’t see someone already reported this ;)

  • http://www.markrushworth.com mark rushworth

    lol great doesnt work in opera 10 – guess i wont be using this so soon in reality

  • http://sailboatvn.com Hung Bui

    oh dear.. I need them now.. cannot wait for 4560 days :( (@http://ishtml5readyyet.com)

    Nicely written article. Cheers,

    Bui

  • http://www.alfystudio.com Ahmad Alfy

    That new syntax scares me…
    I don’t think I’ll be using HTML5!

    XHTML2.0 FTW!

    • http://danharper.me Dan Harper

      Actually, the W3C will be ending development of XHTML 2 by the end of 2009, and moving all resources to HTML5.

      While I preferred certain aspects of XHTML 2, it’s better to have one standard than two!

      • http://www.alfystudio.com Ahmad Alfy

        I feel like XHTML is more consistent!

        what’s the chances XHTML5 will be parsed like an xml docs?

      • http://twitter.com/mads Mads Kjaer
        Author

        @Ahmad Alfy

        If you need to parse your documents as XML, you can still specify the proper “application/xhtml+xml” MIME-type in your HTML 5 document. This turns it into XHTML 5 (yes, the terms are getting confusing).

      • Duluoz

        @Mads Kjaer

        You’re correct. You can still write using XHTML syntax. Though to save bytes, improve maintainability, and simplify things even more – write in HTML syntax, omit optional closing tags and optional attributes, and let’s put more focus on creating happier end-users at all accessibility levels. The only caveat should always be cost(time) vs. maintainability. :)

    • http://www.greatscottcreative.com A. Scott

      @Ahmad Aify – Read Henri Sivonen’s Unofficial Q&A about HTML5 and the XHTML2.0 cancellation. It comes across slightly bitter, but helped clear up my understanding of HTML5.

  • http://www.intadata.eu David Parsons

    Interesting article, thanks.

    Although should you really be going back to using tables for the content? Seems like a step backwards, or is it just me?

    “That’s all! No more floating, faux column background images, clearing or collapsing margins. We’ve made the elements behave like a table, and this makes it much easier for us to do layout.”

    • http://www.intadata.eu David Parsons

      …and I know it’s the styling and not the markup, but it still seems a little awkward. Okay, probably just me *lol

      • Shaun

        Nope, not just you. A lot of us in the development community have called shenanigans. Not like it matters, this won’t be mainstream for another +15 years anyway, lol

  • http://sankar.info Sankar

    The way you explained it is awesome. Great explanation. Starting building a page with your instructions.

    Thanks
    Sankar

  • http://webmuch.com Aayush

    I hope all the developments work faster for CSS3 & HTML5….wish I could use all this already….but it’s still a couple of years to that….

  • http://www.goldfries.com goldfries

    oh interesting. looks like it’s time to pick up more things!

  • http://www.markuppoet.com Amal

    nice post. we are waiting for this. it will be more easier for us to dealing rounded corner and shadow.

  • http://www.gitare.info Tony

    Can’t wait for these babies =) great article ;)

  • http://designi1.com jose pacheco

    Nice article…. we can see how to use some new markups. Keep us posted!!! :D

  • http://www.jsxtech.com Jaspal Singh

    wonderful article on css3, thanks for sharing.

  • http://www.seandelaney.co.uk/blog/ Sean Delaney

    Very very helpful indeed. I found this to be a great a read.

  • http://newelementdesigns.com Don

    I have a question. I thought the tag was intended for the top, in most cases header area of the site, like the tag is for the bottom and not to wrap around ALL already known H1,H2, H3, etc tags. Is this not correct? The H1, H2 etc tags are already known header tags.

    • http://newelementdesigns.com Don

      OK. WordPress replaced the tags in my comment as I knew it would, sorry.

      I have a question. I thought the HEADER tag was intended for the top, in most cases header area of the site, like the FOOTER tag is for the bottom and not to wrap around ALL already known H1,H2, H3, etc tags. Is this not correct? The H1, H2 etc tags are already known header tags.

      • http://twitter.com/mads Mads Kjaer
        Author

        The header-tag is intended for the top of the page, and to describe individual sections.

        In the tutorial I have wrapped a header-tag around a single h2 or h3 tag multiple times. It is not really needed. As you say, the h1-h6 tags are semantic by themselves, and they don’t need an entire header around them. However, I added them for clarity. It is still proper markup.

      • http://www.badcat.com badcat

        Running this through http://validator.w3.org actually comes back with a few errors and warnings re: putting Sections (IDs) and H3 type content in the footer div/tag.

        w3.org also seems to want character encoding type added to pass the HTML5 experimental doctype. Otherwise it’s assumed utf-8.

        I’ve also seen variants of the nav lists using rather than , fwiw.

        thanks for the tut!

      • http://www.badcat.com badcat

        Meh. my code vanished… It was supposed to read:

        I’ve also seen variants of the nav lists using NL (navlists) rather than UL (unordered lists), fwiw. Referring to the nav tag lists.

  • Dylan Parry

    There’s a fair bit of pessimism in the comments I’ve read so far. From what I’ve seen, a lot of HTML5 can already be used, although for IE you need to use a little bit of Javascript to get it working—perhaps there’s a HTC solution out there? If you can live with that, then HTML5 is pretty much usable now.

    As it is, you won’t be able to use the API stuff such as required fields on forms, but that’s not a problem either. Use Javascript to add that functionality to browsers that don’t currently support it, and validate your inputs on the back-end as you should already do so now.

    The solutions to the problem of IE remind me somewhat of Dean Edwards novel “IE7” solution—implement everything that IE doesn’t support by using Javascript instead. I know I’ll certainly be having a go at getting the most out of HTML5 as it currently stands.

  • Jônatan Fróes

    Will ‘divs’ die?

    • http://twitter.com/mads Mads Kjaer
      Author

      Most of them, yes. They are not deprecated in HTML 5, and they still have their uses. Use them to describe a division in the page where there is no explicit section, like they were used in the tutorial to layout the main content area.

  • http://haracz.net haRacz

    Aside is related to content so it should look like

    some text
    and there is aside from section text

    And not like in this example.

    >> what’s the chances XHTML5 will be parsed like an xml docs?
    http://www.w3.org/QA/2008/01/html5-is-html-and-xml