Sickdesigner

My name is Radu Chelariu, I'm a web designer and here you can get to know me better.

Taking semantic tags one step further

Lately it seems that the interwebs have been going all out nuts with HTML5 and CSS3. Everybody’s a pioneer and everybody’s declaring NOW is the time to start using them. But has anyone actually done more than just dip in?

I’m not trying to point fingers here, but one must admit that while there is a growing interest and awareness of HTML5 and CSS3, most agencies and freelancers are just as discrete about them as before.

On the other hand, agencies and freelancers haven’t really been pioneers for obvious reasons: they work for clients. And clients don’t care about the latest and greatest, they care about revenue and WYSIWYG (most have never heard of graceful degradation/progressive enhancement). It’s all about the Benjamins, baby!

Enter the wonderful world of personal pages. I’m referring to design blogs and designer portfolios mostly. These places have, for some very long time now, been a sandbox for testing, learning and experimenting with technology that’s considered “avantgarde”. Though, one must point out the existence of the HTML5 Gallery Showcase, a place to check out plenty of websites using HTML5.

So, in our sickness, we thought: lLet’s do the redesign for Sickdesigner using HTML5 and CSS3. We did, and so much more.

It was a stroke of luck that around that time we came across a mind-blowing post by the one and only John Resig, creator of jQuery. In case you haven’t come across the article or just didn’t click the link back there, it’s all about a nifty little piece of Javascript goodness called document.createElement which John used to portray how one could create and use the new tags in HTML5.

This tiny piece of code made all the difference in our minds, when realizing the potential and usefulness of document.createElement. Here’s a bit of code from this very website:
<container>
   <header>
      <h1>
         <a class="tooltip" id="logo" href="http://sickdesigner.com/" title="The main ward">
            Sickdesigner - The sickness is spreading
         </a>
      </h1>
   </header>
</container>

At this point you’re probably scratching your head a bit. It’s okay, it’s normal. Most of you will recognize the h1 and a tags. Some of you, more familiar with HTML5, will recognize the header tag. But then, right at the very start we have  a tag called container, which doesn’t really belong anywhere.  That’s because it’s generated with document.createElement.

Well, there’s a very good explanation for this: Semantic tags. We’ve all heard of them and, unless you have tables for layouts, you’re using them.

Semantic tags = “use the right tag for the right place”. If you’ve got a paragraph, use a p tag, if you’ve got a line break, use an hr tag. This also extends to classes and ids: if you’ve got a header div, slap on an id of “header”.

We work in an environment which really thrives on progress. And in such an environment it is the opinion of this sick designer that one must always strive to challenge old paradigms. We challenge the term Semantic tag. We want it to actually mean a semantic tag, a tag that means something, that expresses it’s use.

Still not on our side? Check this out:

<container></container>
<div id="container"></div>

Isn’t the first way of writing the container cleaner, more efficient, more meaningful and easier to maintain?

So what other tags did we decide to include? Let’s see now: wrap, container, header, sidebar, twitter, rss, homepage, posts, article, category, tags, footer, single, comments, author.

HTML is a great language which does employ semantic tags in the sense described above, such as p, em, strong etc. But you’ll notice that they are all tags that relate strictly to content, not structure. For that we’re bestowed upon with divs. Ugly, ugly divs, which mean nothing but “a divider”. Sure, the W3C is trying their best to come up with semantic structural tags in HTML5, like header and nav and footer, and that’s peachy fine. But what they don’t understand is that not all websites are built the same. Not all websites have just these elements.

Pop quiz, kids:

Most blogs display their categories. What’s the appropriate tag for a category? And I mean truly appropriate, not a span. Why not have a category tag?

We’ve only used the newly created tags for structural purposes. It’s not an exercise in “look ma, see what I did?”, but an attempt to bring sense and direction to a part of HTML that lacks proper meaning.

The how to part

Now, enough chatting about this stuff. Let’s say you want to implement this kind of weirdness in your next project. How do you go about it?

First, take a piece of paper and write down all of the tags you’re going to create. This is not rocket surgery(!), but planning ahead is essential.

The Javascript

// Create elements
document.createElement("wrap");
document.createElement("container");
document.createElement("header");
document.createElement("sidebar");
document.createElement("footer");

Quite. Save that with a filename of, say, create-elements.js. Let’s include that in our HTML page.

The HTML

<!DOCTYPE html>
<html>
   <head>
      <title>Truly Semantic Tags</title>
      <link rel="stylesheet" href="style.css" type="text/css" media="screen" />
      <script type="text/javascript" src="create-elements.js"></script>
</head>

I’ve also added the HTML5 Doctype declaration and a stylesheet to the equation. Now, let’s move on to the CSS part of the deal.

And the CSS

wrap, container, header, sidebar, footer{
   display: block; }

By default, these elements have no properties and since their use is structural, a display: block is needed for proper rendering.

And there you have it. Now you’re ready to style away at these newly created elements, without added classes/ids and with meaningful names.

But, alas

Of course, we can’t forget about that wretched “old friend” of ours, Internet Explorer.

If you’re thinking about whether this stuff works on IE6…forget about it. It just withers into a corner and starts crying at the very site of the new tags. And it should. I don’t hear any cries of grief over the inability of Firefox 1.5 to render border-radius, so there will be no tears shed for this relic.

IE7 and 8, however, do seem to comply. There are restrictions, though. It seems that IE likes to create self closing tags, instead of normal ones. But there is hope, yet.

You can use Remy Sharp’s HTML5 shiv. It’s a nice little piece of Javascript, which essentially does exactly what we just did, but using the .replace method and some nice regular expressions. Just download and add your own  elements to the list. Like so:

// For discussion and comments, see: http://remysharp.com/2009/01/07/html5-enabling-script/ (credit to @jdalton for minif)
/*@cc_on'abbr article aside audio canvas container details figcaption figure footer header hgroup mark menu meter nav output progress section sidebar summary time video wrap'.replace(/\w+/g,function(n){document.createElement(n)})@*/

This way you can include IE7 and 8 into your supported browsers list.

So, can you use this in a client’s project? Perhaps. We think it’s feasible enough, although it does take some (little) time getting used to it. And if your next project doesn’t imply supporting IE (one can only dream, right?), then this is definitely something you should try.

This whole idea may seem a bit nutty and perhaps it is. But I like to look at us web folk like doctors. We work in an ever changing, nerve wracking medium and all our professional lives we strive to learn newer, better ways of doing what we do, no matter how ludicrous and unreasonable they may seem ar first glance.

by Radu Chelariu

10 Comments

  1. Ricu says:

    These are very good points and it makes the code much much cleaner and easy to modify. Unfortunately you said it yourself : “clients don’t care about the latest and greatest, they care about revenue and WYSIWYG (most have never heard of graceful degradation/progressive enhancement)”

    Until they can be user people need to be educated to upgrade their browsers so that developers and designer can use the new tricks , and clients need to help us more.

    The development of the web resistance is made from people that don’t bother, and i am sad to say we cannot be like them :-( that is why IE6 still roams the web like the ghost that it is.

    PS : This was a post just to kill the no comments monster ! damn monsters they took ‘r jobs !

  2. Edward says:

    Very cool – I’ve been wondering why we use divs and classes for awhile now.. this XML-type HTML is our future :D

  3. This is a very interesting idea indeed.

    One thing that leaves me weary is that its all based on Javascript. What happens when users have this feature disabled?

  4. Victor Bauer says:

    Excellent post! Congratulations!
    the only thing i’m preocupado is the W3C validation…
    The “document.createElement” solves the problem with the browsers and CSS styles. But the HTML code isn’t validated. How can we solve this?
    Thanks

  5. @Victor: Thanks! While building the new sickdesigner.com I too was a bit weary about not being able to validate; to be honest I’m not sure this problem will ever be solved. The way I see it you can overcome this by first creating the website with divs with ids and validating as you would normally and then at the very end replace these with super semantic tags. That way, the code is proper, even though not valid.
    @Ian: it’s true, the code is dependant on Javascript and while disabled you’d run into what I can only imagine as paranormal behavior from older browsers, while the newer class of browsers might be able to cope with the new tags.
    This is all very experimental and while sickdesigner.com is built using this technique, I can live with it because 98% of my visitors have Javascript on and about 90 something procent use modern browsers. So for me, it’s all safe and sound; it depends on your audience.

  6. mansour says:

    this is the sickness.

  7. meilinPR says:

    Using <container> instead of <div id=’container’> does look much cleaner, but I question its usefulness. This would only be good for structural code that is not likely to be taken out of context (unless, say, <i>, which might be read by an RSS reader), but these are tags are not recurrent – that is, not every site needs a container div, and those that do use it will only have one. So, then, why add tags (such as container and sidebar)? And I am always reluctant to use JavaScript.

    Since I am posting, let me say that this is a very nice layout, it’s a while since I’ve seen one like this one (with the holder for the sidebar drawn in the background). But something strange happened. When I was reading the articles on CSS formatting and on KISS, the content went below the sidebar. A case of the container not being wide enough for the two block elements to be side-by-side, I figured, but then I maximized my window (my res is 1400px wide), and it still didn’t look right. Everything is suddenly magically fixed, though, as long as I keep the window no narrower than 1000px.

    By the way, this comment box drives me crazy. Because I don’t know whether I can use HTML, and what tags can use, nor is there a ‘Preview’ button.

  8. @meilinPR: I do agree with you that single-occurence elements could be left to the HTML standards, but let’s consider an example – a car parts manufacturer. In this example, a page may display 10 exhaust pipes, 10 gear shifters, 10 transmissions etc. In this case, perhaps using super-semantic tags isn’t a bad idea. Still, super semantic tags are obviously experimental and not a go-to fix. It’s a radical idea that will, probably, never leave the confines of this website. But they’re still damn cool!
    Thanks for the layout pointers, it seems they came just in time, as we’re in the middle of a code overhaul on the website. We’ll through your thoughts into the pot and see what comes out ;)

  9. John Darling says:

    Very cool idea! I am dabbling with html5 these days and I love the more semantic tags as opposed to divitus (use of divs, ids and classes). Not validating concerns me a little. As for the lack of support for browsers not using js, well thats going to be an issue for any html5 site that is viewed on a non-supporting html5 browser not running js…whoa that was a kind of a tongue twister lol (e.g. early IE).

    Anyway this is the first post i’ve read here, and i will be sure to stay tuned for more.

    Sick stuff! :p

  10. Jamie says:

    In many situations, it is simpler to just use classes and IDs on existing semantic elements. An element like “twitter” wouldn’t be used nearly as often as the existing “header” tag, and even has the potential (however small) to eventually become obsolete. Because of this, dedicating time to documenting and supporting arbitrary elements would be quite inefficient.

Speak your mind

RSS Twitter Facebook Dribbble LoveDSGN Flickr