
In the first article in this series, Content before Design, I discussed the approach to take when building sites structured in accordance to their raw content as opposed to their presentation. In part 2, I’ll be looking at how to use semantic markup and which XHTML elements are best used for different types of content.
What is semantics?
I used to naively believe that semantic markup was just clean, well-formed HTML with divs and uls instead of tables. I thought it was a term I could throw at clients and such to look clever. But although semantic markup is so much more, it is in essence very simple. Semantic markup is that which conveys meaning and the purpose of the content it contains. So, headings should be correctly wrapped in <h*> tags, unordered lists in <ul> tags and so on.
Semantics is meaning.
Well, ‘that’s just plain common sense’ you may be thinking. And of course you’re right! But regardless, the majority of websites are built so solidly around their design as opposed to content – you’d be amazed how many times obvious lists are created in paragraphs with line-breaks instead of in individual <li> tags. Or take this very site for example – the header logo is simply an image, no <h1> tag – although it’s obviously the top level heading.
“I will be fixing this elementary issues on the next redesign, I feel it’s good for the purpose of writing such articles to be able to point out my own mistakes.”
Making meaning
HTML provides us with around 40 tags to markup different types of content. This may have been dandy 15 years ago, but in light of the web’s immense expansion and the superfluity of different forms of media and content websites present – 40 tags looks rather slim. The result of this is 2-fold, either:
- designers look to alternative methods, such as microformats, to help expand the capabilities of their markup.
- designers are forced to use irrelevant HTML tags to contain and present content they weren’t originally intended for.
So, in some cases it’s 1 step forward, but in others it’s practically 2 steps back.
The easiest way to write semantic markup is to build sites with a content-out approach, as discussed in part 1 of this series. By writing your XHTML in a logical content order – you will automatically create the correct elements to represent the content of your site instead of the design.
Why is this important?
Well, not to bore you with the old accessibility argument but let’s not forget that websites are, in their rawest forms, conveyors of content to the user. Sure, we use CSS to make them look darn pretty and then we pop in a bit of client-side scripting or Flash to make them sparkle – but there’s a large portion of your visitors that won’t reap the benefits of all that time spent in Photoshop and writing lines of funny symbols.
Writing meaningful markup helps to group different content types correctly. When styles are disabled, or when your site is being parsed by non-visual devices, this will help to keep everything together and in order. However, it also aids styling to no end, and can also make it easier to associate elements and content types with scripting to easily control the dynamic and visual effects of entire blocks of content without having to assign various classes and ids to every item.
In the following example I have changed my current footer navigation markup into semantic, meaningful HTML that can now be styled more easily than when each footer link was independent of every other:

What’s better about it?
- Firstly, I’ve removed the useless <div> and marked up the internal contents (the list of links) in an unordered list.
- I’ve then replaced the <div> id with a more meaningful <ul> id. This will mean some CSS amends to transpose the styles.
- Doing this gives me more stylistic control over the elements with less code, but also means that without styles, the content will still make sense.
Simple eh? That’s the point! Creating semantic markup shouldn’t be an exceptional skill, it really is just a combination of a good knowledge of HTML and common sense. The new footer markup above is actually easy to control with CSS and will now appear far more coherently when viewed without styles.
Using the correct elements
It’s important to consider carefully which elements to use when marking up content. This can reduce bloated code in files, make CSS styling easier, aid dynamic control, make it easier to aggregate data to different sites and apps, and most importantly ensure that the content makes sense when all styles and scripts are off.
A few examples of incorrect uses of HTML:
BAD:
<p>This is a paragraph of information.<br /><br />This is the second paragraph of even more information…</p>
GOOD:
<p>This is a pararaph of information.</p> <p>This is the second paragraph of even more information…</p>
Ok that’s fairly obvious. What about when incorrect elements are used for styling before the true nature of the content has been considered:
BAD:
<span>”Knowledge speaks, wisdom listens.”</span>
<br />
<strong>Jimi Hendrix</strong>GOOD:
<blockquote>
<p>Knowledge speaks, wisdom listens.</p>
<p><cite>Jimi Hendrix</cite></p>
</blockquote>
And one more chunky example for good measure:
BAD:
<strong>PHOTOSHOP FOR BEGINNERS</strong>
<p>Photoshop is a design package by Adobe that allows you to create and manipulate images and photography. Some of things you can do with Photoshop include:
<br /><br />
<strong>Cropping, rotating and resizing images.</strong><br />
<strong>Changing the lighting, brightness, contrast, hue and saturation of images.</strong>
<strong>Create shapes and objects and apply gradients and shadows.</strong>GOOD:
<h1>Photoshop for beginners</h1>
<p>Photoshop is a design package by Adobe that allows you to create and manipulate images and photography. Some of things you can do with Photoshop include:</p>
<ul>
<li>Cropping, rotating and resizing images.</li>
<li>Changing the lighting, brightness, contrast, hue and saturation of images.</li>
<li>Create shapes and objects and apply gradients and shadows.</li>
</ul>
Marking up with Microformats
Microformats are a set of open data format standards to help create and ease web content publishing and transferring.
They are designed to more appropriately label groups of data, such as an address or business card information. They are an extension of XHTML that open up a lot of opportunities with only the slightest bit of code. No new languages to learn, no complex scripting.
Microformats extend the potential of the traditional 40 (or so) HTML elements such as blockquotes, paragraphs and lists and enable us to describe and markup our content in even greater detail. They also allow us to markup content so it can easily be aggregated by other sources through XML, RSS and other technologies.
Now unfortunately I’m going to stop there before I embark upon another tangent on Microformats. They are most certainly a subject for another day, considering I’ve recently got the bible on Microformats for Christmas and it’s going to take a while to get through. So for now, please pop over to the Microformats website for lots and lots of more information!
Take a step back
Well, that about covers that for now. In the past 2 articles we’ve looked at designing from the ground up. Considering content first before fancy graphics and snazzy AJAX and Flash and looking at how to markup our XHTML correctly and semantically. In the 3rd part in this series I’ll be entering the deep realms of progressive enhancement, but until then I’d like to hear your opinions and views, so feel free to comment away!
enjoying this series so far! Keep up the good work
I too am enjoying this series. It outlines and goes into some detail, the “correct” methods for constructing and marking up websites.
It is the very reason why I disagree with all the hype about display:table which forces you to write your markup for the css.
This is why I needed to express myself with this website:
http://isdisplaytableabadidea.co.uk/
Keep up the good articles
Stephen
Nathan
Couldn’t agree with you more, semantics is not some dark art but pretty simple really.
Like yourself I’ve found myself looking back at some of my old HTML recently (my personal site from 2005 included) and wondering what I’ve been thinking. The amount of times I’ve wrapped an uneccessary div around a ul is unbelieveable.
A process I’ve now found useful is to write the plain HTML first before assigned any styles, that way I can make sure that I have the content in the correct order and with the correct semantic meaning. Once I’m happy with that I can start to go ahead and add the CSS.
Lastly, don’t forget that with HTML5 on the (distant) horizon this will open up more tags and more semantic meaning. See http://www.w3.org/html/wg/markup-spec/ for more.
Look forward to part 3.
Rich
@Nathan, yeah I saw that one here’s hoping they will figure it out before it becomes a recomendation. I think I also need to get my hand on that Microformats book.
Other articles that you and your readers may or may not have seen re HTML5 can be found here:
Andy Clarke: developing naming conventions
Jeremy Keith: The Rise of HTML5
Eric Meyer: An Event Apart and HTML5
Pingback: Findings 1.10.09 | 8164
It’s unfortunate that whether it’s time constraints or something else, we sometimes do not take enough time to sit back and think for a second about something that when stripped back (as you have done) is SO simple and SO logical!
Thanks for reminding me to start taking that extra time again. I’m sure it will be worth it in the long run.
Craig
Nathan,
I’m a newbie on web designing.
I think I got the point from this post, I’ll try to fix some codes. Thanks.
Here I come semantic world.
Cheers for the comments guys. It’s funny thinking about what I’ve mentioned in the article and the conversation Rich and I had in the comments – only yesterday I put a single image in a div to position it absolutely in the corner of the site before realising there was absolutely no point for the div whatsoever!
Ahh… you live and learn
I’m aiming to get part 3 together this week if I get time, if not it will definitely be next week. Thanks!
its…true…css plays a great role…your article is great
Hey guys, glad to hear you’re enjoying the articles, sorry it’s been nearly a month since the last, I’ll try to get part 3 out sooner.
@Rich – it’s true that HTML5 will offer more semantic, meaningful elements but a recent article John Allsopp on A List Apart finds flaw in HTML5 and looks at other methods of adding meaning, I recommend checking it out.