Monday, December 15, 2008

HTML 5 Basic Template

Since HTML 5 is likely to be in common use at some time in the future (taking advantage of current/future web browsers standards rendering mode) and the W3C validation service now validates HTML 5.

<!DOCTYPE html>
<html>
<head>
 <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
 <title>Site | Page 1</title>
</head>
<body>
 <div id="outer">
  <div id="top"></div>
  <div id="inner">
   <div id="header"><h1>Page 1</h1></div>
   <div id="navigation">
    <ul>
     <li class="current"><a href="#">Page 1</a></li>
     <li><a href="#">Page 2</a></li>
     <li><a href="#">Page 3</a></li>
    </ul>
   </div>
   <div id="content">
    <p>Lorem ipsum dolor sit amet...</p>
   </div>
   <div id="footer"><a href="#top">Top of page</a></div>
  </div>
  <div id="bottom"></div>
 </div>
</body>
</html>

Note: the Content-Type meta element has to be the first element under the head element to validate. In HTML elements can be optionally self closing (so <br /> and <br> are both valid.

Notice that there are 'top' and 'bottom' elements in the markup? They are used to allow the margin-top/bottom for the 'inner' <div> to work in Firefox. 'top' also functions as an anchor to get back to the top of the page.

Example of CSS that can be used with this template:

body {
 color: #000;
 background: #fff;
 margin: 0;
 padding: 10px
}

#outer {
 width: 960px;
 margin: 0 auto;
 background: #eee
}

#top {
 padding-bottom: 1px; margin-bottom: -1px /* force #inner margin-top to take effect in Firefox/WebKit */
}

#inner {
 margin: 3px; /* margin: 0 3px 3px 0; for drop shadow effect */
 border: 1px solid #009;
 background: #fff
}

#header { background: #eee }

#header h1 { margin: 0}


#navigation {
 background: #eef;
 width: 100%;
 overflow: hidden;
 border-width: 1px 0 1px 0;
 border-style: solid;
 border-color: #009
}

#navigation ul {
 margin: 0;
 padding: 0;
 list-style-type: none;
 float: right
}

#navigation ul li { float: left }

#navigation ul li a:link,
#navigation ul li a:visited {
 display: block;
 float: left;
 padding: 3px;
 zoom: 1 /* force hasLayout in IE */
}

#navigation ul li a:hover {
 background: #000;
 color: #fff
}

#navigation ul li a:active,
#navigation ul li.current a:link,
#navigation ul li.current a:visited,
#navigation ul li.current a:hover {
 background: #aaa;
 color: #ffe
}


#content { padding: 3px }

#footer {
 padding: 6px;
 border-top: 1px solid #009
}

#bottom {
 padding-top: 1px; margin-top: -1px /* force #inner margin-bottom to take effect in Firefox/WebKit */
}

3 comments:

web development los angeles said...

Thanks for sharing the code and the example of CSS. This will help me a lot.

kimberly ventura

los angeles web design said...

Great intro to HTML 5.

Tom

David Kreuter said...

When using HTML5 you should use tags like <nav> and <footer> instead of <div id="nav"> and <div id="footer">