Guide to Semantic Mark-up

August 22, 2006 | Published in: Accessibility, Standards & SEO | Tags: , , , , 23

Image of a tagMany people make the mistake of using tags for appearance only in their websites, but with semantics you get the benefit of describing your data as well. This makes it more accessible and of a higher quality, and of course fulfills the main objective; separating content from presentation.

This article is aimed at semantic mark-up beginners, including clients who want to learn more about code so they can ensure their sites are semantically correct. It also shows the mark-up available and it’s usage.


What is Semantic Mark-up

In web development, Semantic Mark-up is the name given to ‘marking up’ (coding) your sites with code that represents the information contained in elements, and is descriptive. More importantly, in my opinion, it makes reading code much, much easier because you can see and understand what is happening, rather that being swamped with meaningless code.

An example would be, say I wish to make an important point stand out by making it bold.
I could use the <b> tag, but as ‘b’ says nothing about the content it holds it is not semantically correct, it simply tells the browser to render the text in bold.

The semantic way would be to use <strong>, as it tell you that the contained code is important and ’strong’.

Another example is <i> for italic, it doesn’t explain what the content represents, however the <em> tag does (emphasis).

Another aspect of semantics is using the correct tags for the correct content, for example, if I want to make a bulleted list I would use the <ul> tag (unordered list). If I wanted to have a main heading I would use the <h1> tag (heading 1).

Why bother

There are many valid reasons for making your mark-up semantic, rather than presentation based, here are the main points in my opinion.

Ease of updating

At some point you are going to want to update the look of your site, making your site semantic will make this task seriously simpler. Take this for example, say you have a site with many pages with lists of content on them, and you want to make the list items have uppercase text, but you have used presentational mark-up:

<p>
-	list item</br>
-	list item</br>
-	list item
</p> 

To do this you would have to go through all of your pages, updating the content to have upper case letters instead of lower. Ouch.

Now consider you used an unordered list:

<ul>
<li>List item</li>
<li>List item</li>
<li>List item</li>
</ul>

Now you could convert to upper case with a simple line of CSS, without touching the mark-up itself.

ul {text-transform: uppercase ;}

Simple, separating content from presentation is definitely beneficial.

Presentational mark-up is inaccessible

Presentational mark-up does nothing to say what the content it holds is for. This can reduce understanding, and meaning, of the text.

You can look at this from a few different ways.

To someone reading the code, for example a web programmer, if a code is presentational it makes it very hard to make sense of. For example:

<font size=”14px” color=”#000”><b>Welcome to the site</b></font>

This would mean very little to anybody reading. What is the text for? What does it represent? The semantic, better way would be:

<h1>Welcome to the site</h1>

Now it actually means something, it is a heading.

You can also see that in the above example the semantic code was much more organised and compact, and would make the file size lower.

Computers understanding the content


If a program wants to understand the code, presentational mark-up does little to help. Semantic mark-up however describes the content making it much easier and more meaningful to a program.

An example would be a screen reader program for the blind. They would not benefit from the presentation of an element, they would rely on what the element is to make sense of it, therefore semantics would be very important in that case.

You should also realise that search engines need to read you page, so by impoving your site’s semantics you are also improving your visibility to the search engines.

Search engine optimisation

Most search engines weight keyword importance by what they are e.g. paragraph text. By using semantics you are essentially telling the search engine what is important, and what is less important. For example, keywords in the headings are deemed more important than keywords in the paragraphs.

Semantic elements – A guide

This section describes and lists common elements, and what they should be used for in web documents.

Block-level elements

Block level elements usually render on a new line, and can contain inline elements and other block elements.

Headings

The heading elements (h1, h2, h3 and so on) should be used for headings in your document.
As the heading number increases, the importance of the heading is reduced.

As a general rule, it is wise to use <h1> once, for the main page title, then use h2 and possibly h3 for the page headings.
But remember, what ever you do, keep it consistent.

Paragraphs

Paragraphs of text should always be wrapped in the paragraph (<p>) tag. The ‘p’ tag. By default, starts on a new line, so this is the correct method of making paragraphs; do not use the <br /> element to do the same thing, as this is not semantic. Example:

Correct usage:

<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus libero felis, iaculis vitae, elementum id, laoreet sit amet, elit. Cras iaculis aliquet augue.</p>
<p>Quisque lacus velit, tempus at, faucibus eget, lacinia id, libero. Duis aliquam, eros a consequat imperdiet, sapien ante ullamcorper sapien, id venenatis lacus augue in lorem.</p>

Output:

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus libero felis, iaculis vitae, elementum id, laoreet sit amet, elit. Cras iaculis aliquet augue.

Quisque lacus velit, tempus at, faucibus eget, lacinia id, libero. Duis aliquam, eros a consequat imperdiet, sapien ante ullamcorper sapien, id venenatis lacus augue in lorem.

Incorrect usage:

<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus libero felis, iaculis vitae, elementum id, laoreet sit amet, elit. Cras iaculis aliquet augue. <br />Quisque lacus velit, tempus at, faucibus eget, lacinia id, libero. Duis aliquam, eros a consequat imperdiet, sapien ante ullamcorper sapien, id venenatis lacus augue in lorem.</p>

Output:

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus libero felis, iaculis vitae, elementum id, laoreet sit amet, elit. Cras iaculis aliquet augue.
Quisque lacus velit, tempus at, faucibus eget, lacinia id, libero. Duis aliquam, eros a consequat imperdiet, sapien ante ullamcorper sapien, id venenatis lacus augue in lorem.

They make look the same, but the 2nd is not semantically correct, and also does not separate content from presentation, as you are forcing the presentation to be changed with a ‘break’.

Blockquote

Quotation

Used, usually along with ‘cite’, to quote a source of information. By default, the block quote element is displayed as a block level element, and has margins/indentation.

Blockquote can also have the attributes title and cite. Even though it has a ‘cite’ attribute, not many browsers use this, so it is wise to use the ‘cite’ element with it also, so the source is visible.

Example:

<blockquote cite="http://www.source.com">
<p> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus libero felis, iaculis vitae, elementum id, laoreet sit amet, elit.</p>
<p><cite><a href=" http://www.source.com ">http://www.source.com </a></cite></p>
</blockquote>	

Output:

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus libero felis, iaculis vitae, elementum id, laoreet sit amet, elit.

http://www.source.com

Inline Elements

Inline elements can usually only contain text, and other inline elements. They do not begin on a new line, like block elements.
I will outline the most common elements, with alternatives for use if you just want to change style; do not use these tags if you are just after the styling and not the meaning of the tag.

Abbr

abbreviated text

The ‘abbr’ tag is used to mark-up abbreviations, and by using its ‘title’ attribute you can display the full meaning as a tool tip.

Acronym

acronyms

The acronym tag works in exactly the same way as the abbr tag, but is specifically for acronyms.

Cite

Citation

Used for referencing a source of information.

Code

Computer code

The code tag should be used when displaying an extract of code, by default some browsers render it in a mono-space font such as courier.

Del

Deleted

If you delete, or retract, some text on your page, but still want it visible, you should use the ‘del’ tag. By default, most browsers show deleted text with a strike-through.

Del can also be a block-level element.

Alternative: <s> or <strike> – strikethrough tag (deprecated), alternatively use CSS – text-decoration: line-through;

DFN

Definition Term

The ‘definition term’ tag is quite uncommon, but is used for defining a term for the first time in a document. It can be used with the title attribute to define its contents.

Example:

<dfn title="Opera's web browser">Opera</dfn> is available on desktop pc's and mobile devices.

Output:

Opera is available on desktop pc’s and mobile devices.

EM

Emphasis

Used for emphasising the text inside. By default the emphasised text is represented with an italic style.

Alternative: CSS – font-style: italic ;

Ins

Inserted text

This tag can be used to identify text you have inserted at a later date, and is especially useful when using along with the ‘del’ tag, so show what you have replaced the deleted text with.

Ins can also be a block-level element.

Kbd

Keyboard instructions

This tag is for marking up keyboard instructions for the user to perform.

Samp

Sample output

This rarely used tag is for marking up sample output from a program/script, for example an error message in windows.

Var

Variable

The ‘var’ tag can be used to indicate a variable name when writing about computer code.

Example:

The users name is stored in <var>$name</var>.

Output:

The users name is stored in $name.

Strong

Stronger emphasis

Used for a stronger emphasis on the text inside. By default the ’strong’ text is represented with a bold styling.

Alternative: CSS – font-weight: bold;

Lists

There are three types of lists:

UL
Unordered lists, a.k.a bulleted lists. Use these when your list doesn’t need to be numbered. List items in the unordered list are specified with the ‘li’ tag. A popular usage is with navigation links, as they are listed in a ul (and usually styled with css). The blue anvil navigation bar is a UL.
OL
Ordered lists, a.k.a numbered lists. Use this when you want list items (defined again by ‘li’) to be numbered.
DL
Definition lists. These use the tags ‘DL’ (Definition list), ‘DT’ (Definition term), and ‘DD’ (definition description), and are used to show terms and definitions. The list you are currently reading is a definition list! See below for the code.

Definition list example

<dl>
<dt>Term</dt>
<dd>Term definition.</dd>
<dt>Another term</dt>
<dt>Another term</dt>
<dd>Definition for both terms above.</dd>
</dl>

Output:

Term
Term definition.
Another term
Another term
Definition for both terms above.

Ordered list example

<ol>
<li>List item</li>
<li>List item</li>
<li>List item</li>
<li>List item</li>
</ol>

Output

  1. List item
  2. List item
  3. List item
  4. List item

Unordered list example

<ul>
<li>List item</li>
<li>List item</li>
<li>List item</li>
<li>List item</li>
</ul>

Output

  • List item
  • List item
  • List item
  • List item

Basic Semantic examples

Code listing Example

If you wanted to show some code on your web page, to do it semantically you could do the following.

<code>$name = 'Bob'; $name.=' Smith';</code>
When you echo <var>$name</var> it will display <samp>Bob Smith</samp>.

Example Output

$name = 'Bob'; $name.=' Smith';
When you echo $name it will display Bob Smith.

As you can see, the code is easy to read and is clearly labelled, even if the difference to the presentation is minimal.

Navigation bar example

A well laid out navigation would look like the following:

<ul id=”navexample”>

<li><a href="http://www.blue-anvil.com/index.php" >Journal</a></li>

<li><a href="http://www.blue-anvil.com/services” >Services</a></li>

<li><a href="http://www.blue-anvil.com/contact">Contact</a></li>

</ul>

Un-styled, this mark-up will output like this:

The list based navigation could then be styled via CSS to change the look, read on for more information.

CSS the holy grail

So far this article has focussed on the mark-up of the web page, but it doesn’t end there. Now you know how to write a solid base for a page, you can style the presentation using the power of CSS. This section has some examples.

How to style an element

To style an element, just put the element name in your css document and add styles, for example, have you noticed my ‘code’ elements?

Code goes here

To achieve this effect, I have the following in the style sheet:

code{ styles go here }

This applies to all of the semantic tags, style as you please!

Closing statement

I hope this article has helped give you an insight into the world of semantics, and that the points raised benefit you web site’s design.

Feel free to leave any comments related to this article!

Further Reading

I recommend DesignBits “Create a Semantic web page” as a good follow up to this article.

Found this post useful? Why not buy me a coffee!

Related Entries

23 Responses to “Guide to Semantic Mark-up”

RSS feed for comments on this post.

  1. Mark says:

    Very nice write up.

    Comment made on February 9, 2007 at 5:47 pm

  2. Anthony says:

    A great overview of semantic tags – I will definetley be linking to it for reference. Great Work!

    Comment made on February 9, 2007 at 5:48 pm

  3. João Craveiro says:

    This is the article that brought me here in the first place, and I must admit: it’s great, both as idea and as result— but one thing I just now noticed:

    &lt;strong&gt; — Alternative: CSS – font-weight: bold;
    &lt;em&gt; — Alternative: CSS – font-style: italic;

    This is exactly opposite to the notion of semantic markup and separation of content and presentation. Strong is not bold, emphasis is not italic.
    strong is strong emphasis (which UAs “just happen to” render as bold), and em is normal emphasis (which UAs “just happen to” render as italic). Bold and italic—respectively—are not alternatives to strong and em, they are just “visually equivalent counterparts”, which lack, precisely, the semantic value of the former.

    More specifically, for example, presentational italics (&lt;i&gt; or &lt;span style="font-style: italic;"&gt;) is useful for signaling foreign words (e.g., English words in the middle Portuguese text), since HTML lacks an element with that specifical semantics (I use another alternative: &lt;span lang="en" xml:lang="en"&gt; with appropriate CSS, but it lacks universal support from UAs).

    Comment made on February 9, 2007 at 5:49 pm

  4. Mike J says:

    I used the css for the em/strong alternatives because im fairly sure both the b and i tags are depreciated, so personally I use a span, but I see where you are coming from.

    Comment made on February 9, 2007 at 5:51 pm

  5. João Craveiro says:

    Mike, just to clarify: I wasn’t criticizing the use of CSS instead of b/i. I was criticizing the fact that, in an article focused on semantic markup, referring to presentational ways of achieving bold/italic as alternatives to strong/em is an abuse of language that borders being plainly and simply wrong.

    Comment made on February 9, 2007 at 5:52 pm

  6. Mike J says:

    I should have worded my article differently, the alternatives arnt there as an alternative to the semantic markup; that would be wrong as you said.

    The alternatives are there so people who just want the presenation can do so, without abusing the semantic tags.

    I did this because I see people using <em> <strong> etc when they shouldent be emphasized; they use them purly for their presentational properties, which is wrong.

    Comment made on February 9, 2007 at 5:53 pm

  7. João Craveiro says:

    Oh, in that case, I rest my case, we aparently agree :) —you’re right, the wording gives the wrong impression.

    Comment made on February 9, 2007 at 5:54 pm

  8. Lawsy says:

    Nice writeup, its a shame they don’t teach things like this in ICT classes at my school. I don’t take ICT myself but when I saw some of my friends websites who received top marks for their work. I checked out the source and found it didn’t even have a head section.

    How on earth can you get top marks with non-semantic markup? Its because the teachers don’t even know whats right and wrong on the web.

    Comment made on February 9, 2007 at 5:59 pm

  9. Mike J says:

    I know the feeling, as a student myself, I’m often shocked at what the lecturers teach.

    Comment made on February 9, 2007 at 6:00 pm

  10. Jonathan says:

    Hey, excellent write-up Mike. I’ll be passing this along for reference. Keep up the good work! :)

    -Jonathan

    Comment made on June 17, 2007 at 12:28 pm

  11. Walid says:

    I’ve heard the terms “semantically correct”, but would it also be correct to say “correct semantics”?

    Comment made on June 30, 2007 at 12:58 pm

  12. Mike Jolley says:

    Walid – Erm, ye I think so.

    Comment made on July 1, 2007 at 9:03 pm

  13. Brent says:

    Great Article. I’m reading whatever I can about semntic mark-up at the moment. This is a great start. Now I need to find something than can put everything you have shown here into a real life example.

    By the way, Code listing example is missing a end tag.

    Comment made on July 21, 2007 at 1:16 pm

  14. ludo says:

    I am interested in the topics discussed but have been feeling a little intimidated by the thought of the work

    Comment made on August 8, 2007 at 10:46 pm

  15. Darren says:

    I’m a huge fan of being semantically correct and you have done a great job of describing it. Good examples and a well written article.

    Comment made on August 18, 2007 at 8:58 am

  16. kunter ilalan, web developer - izmir says:

    I’d wish this paper was published 4-5 years ago and I had read it in my return to web design. When I had left, tables were the core structural elements and the font tag was the primary design element besides 1 px transparent GIF’s and NO_BLANK_SPACE chars – &amp;nbsp;.

    I remember I strived 4 months to understand how I could turn the thing around only using CSS due to the difficulty in the case I was in: UNLEARN WHAT YOU HAVE LEARNED

    Comment made on September 8, 2007 at 4:13 pm

  17. femmebot says:

    In the example under “Ease of Updating”, you’re not using proper self-closing break tags. The slash should come after the br, not before.

    Comment made on September 23, 2007 at 6:35 pm

  18. Chris Boswell says:

    One of the best articles I’ve seen on semantic markup. People generally just don’t get taught this stuff, because even those who teach it, are often reliant on Dreamweaver, FrontPage and their ilk. Handcoding has always been the way forward.

    There’s a link coming your way soon.

    Comment made on November 9, 2007 at 7:41 am

  19. ngarrison says:

    In the navigation unordered list styling example, the list that appears after “applying” the style (“Our navigation list now looks like this:”) doesn’t look any different than the original list in either Opera or Firefox.

    You have the class set on the element: but I don’t see a stylesheet (internal or external) that defines the styles for navexample. You place the css on the page but don’t actually use it for the example. I had to edit the source and add this block to the top of the page for the example to work:

    Ul#navexample { list-style:none; margin:0; padding:0; width:200px; }
    Ul#navexample li { margin:0; padding:0; padding-bottom:2px; display:block; }
    Ul#navexample li a{ display:block; text-align:center; padding:4px; background-color:#111; color:#fff; }
    Ul#navexample li a:hover{ Background-color:#444; }

    Comment made on July 15, 2008 at 5:21 pm

  20. Mike Jolley says:

    This post is very old, It probably got deleted when i moved servers

    Comment made on July 15, 2008 at 5:22 pm

  21. Ervin Ter says:

    After reading this article, I get to know more about important of semantic way of coding html. Thanks a lot.

    Comment made on November 12, 2008 at 4:32 am

  22. Vekta says:

    Reading this article has made me think of how complex web programming used to be when I first started work in the industry, over 15 years ago.

    Comment made on March 10, 2009 at 1:28 pm

The comments are closed.

About this site

Blue Anvil is the online web design journal & portfolio of , a web designer from Norfolk, England. Read More »
ThemeSlice
  • Featured work - More

    • Beefjack
    • Integrity
    • theotaku.com
  • Latest Tweet - More

    • New blog post: MiniCard 1.1.7 Update http://blue-anvil.com/archives/minicard-1-1-7-update/
  • Out of the blue - More

    • MiniCard 1.1.7 Update

      I have just uploaded 1.1.7 of MiniCard here and to the WordPress theme directory. This updates includes:

      • New networks; xing, gowalla, yelp, foursquare, mobileme, google buzz
      • A way to change link text and define multiple links of the same network
      • A way to define your own custom links + icons
      • Improved admin panel

      Hope you like it, and don’t forget you can show your support by purchasing the premium pack from here.

    • Switched: From Shared to VPS

      It’s been about two weeks now since I made the transition from a shared reseller hosting account to a VPS (Virtual Private Server) account – impressions so far, excellent performance but fiddly to configure.

      The reason I wanted to change from shared hosting was the fact the server was always being hacked (even though ALL my scripts were secure), there was frequent downtime, support blamed me for problems every time, and it was slow as hell.

      Those used to a shared hosting environment would probably not know where to start when faced with configuring a VPS. Luckily, a lot of it was pre-configured when I received my account – certainly some of the major security holes were patched. I was not satisfied with those however. As a victim of hacking in the past (previous host swears it was not there fault, something I don’t believe) I took extra care to secure it as a much I could – configuring brute force detection, the firewall, installing mod security (excellent rules for that here: http://www.atomicorp.com/wiki/index.php/Atomic_ModSecurity_Rules) and going though multiple guides (like this one: http://www.webhostingtalk.com/showthread.php?t=468168) with a fine-tooth comb.

      The result? My pages are loading at least 6 times faster, I have had no down time (or at least have not noticed any), and I feel in control and happy. No longer am I at the mercy of shared hosts :)

      If your interested, I chose ServInt as my provider as they offered a great deal, as well as being a managed service (so I’m not on my own if I screw things up). I was tempted by the bells and whistles of Media Temple, but felt the ServInt service was better value.

    • Download Monitor 3.2.2 Maintenance Release

      Download Monitor has received some more love and has been updated. Here’s the change log from the new version:

      • Small bugfix in uploader.php – cat ID
      • Changed stats graph calculation – thanks lggemini
      • Changes to headers in download.php to avoid caching
      • File Browser fixes – $root was clashing with something….
      • exclude_cat works in all sections of download_page now
      • Removed hardcoding of /uploads/
      • Added action to download.php – should be able to use it to stop a download if you want – maybe limiting downloads per day or something? Whatever you want…
      • Made it so if you post new file on ‘edit’ screen, the post date is updated.
      • Fixed the ‘blank meta’ section which blanks out custom field values when nothing is set.
      • Moved ‘allow_url_fopen’ check.
      • Someone said downloads don’t work with spaces in the name. They do! Wasting my time sonny…
      • All work and no play make jolley a dull boy
      • Had to rename capabilities so they work. Apologies if you have to set this up again! Cheers to Mark Dingemanse.
      • {category_ID} custom format tag added. Useful if you want to send someone to its category on the DL page I guess. Also added {category_other} so when no category is set “other” is shown – this is because the download page can show an ‘other’ section if you want it to.
      • You can now manually edit the post date on the edit download screen.

      If you have edited capabilities for download monitor user permissions, you’ll have to again sorry! This is because I named them too long. Also, you should check your forced downloads still work because there was a logic error meaning they may not have been forced after-all…

      Enjoy.

    • Mahousive update to Download Monitor (3.2)

      Today I completed the update for the Wordpress Download Monitor Plugin – many tweaks, fixes, and features added. There were no changes to the database structure so people upgrading should be fine. Here is the list from the change log:

      • {user} tag added for custom formats
      • ‘autop’ option fix
      • Download page buttons applied with CSS so they are easier to customise/translate.
      • Fix for pagination bug after editing a download
      • Category output fix on edit downloads screen
      • Category urls on download page use ID rather than name to prevent errors when cats have the same names.
      • exclude_cat added to download_page shortcode
      • Localised ‘hits’ ‘date’ ‘title’ on download page
      • Option to disable the download logging
      • Read file ‘chunked’ some people found large files were corrupted so this should help (fingers crossed)
      • Added show_tags option to download page – displays x amount of tags on the download page.
      • File Browser root setting and download.php logic/mime types modified thanks to Jim Isaacs (jidd.jimisaacs.com)
      • Interface Improvements
      • Bulk edit categories, custom fields, tags, member only downloads
      • Added roles for download monitor admin – should be able to use with a role manager plugin if you want anyone other than admin to access the admin section e.g. http://wordpress.org/extend/plugins/capsman/
      • Change redirect after add
      • Edit Cat names/parents
      • Dedicated tags and thumbnails fields (they still use meta table though)

      And yes, those category link bugs are fixed at long last, and you can edit category names finally. Phew!