Friday, January 21, 2005

Semantic Markup (CSS, HTML)

Hixie's Natural Log: <div style="font-weight: bold">Lost cause</div>. Makes a good point. Why change from deeply nested <table> tags and liberal use of <font> tags to deeply nested <div> tags and inline css (the code, although taking up less disk space, is still untidy) when it is better to design pages semantically (i.e. the code is self descriptive and content truly is seperated from layout). It is easier to modify as well, and any kind of layout can be designed using CSS. So instead of:

<div id="leftfloat">
Menu here...
</div>
<div id="middle">
Contents here...
</div>

You do:

<div id="navmenu">
Menu here...
</div>
<div id="contents">
<a name="contents"></a>
Contents here...
</div>

That way if you decide the menu needs to float to the right, or be below the content then it makes more sense (you can also apply a style switcher to the site as well). Have added an anchor tag as well to contents. The anchor tag was added to allow the user to can skip to the contents by adding the following to the top of the page (above navmenu):

<div id="skipmenu"><a href="#contents">Skip Menu</a></div>

CSS for skipmenu (which hides the link from browsers that lack the proper CSS support)

#skipmenu {
	display: none;
}

Jeffrey Zeldman's site is a good example of semantic markup: http://www.zeldman.com/

It is much better to do this right the first time (i.e. when doing a new site, or redeveloping an old one), rather than try and fix an existing, poorly marked up site.

No comments: