Why use semantic class names?

Posted on 06 February 2007 (04:48 PM)

In the new Dutch accessibility law I recently linked to, one of the guidelines is Use semantic and descriptive classnames and ids.

Why? A lot of web standards / accessibility advocates talk about this subject and everyone mutually agrees that this indeed should be pursued. I don’t get it… why should I care?

Who cares, really?

I don’t believe users will take a peek at your source code to see if the content they’re looking at is contained in markup with meaningful class names. As far as I know there are no user agents flabbergasting their users with information about class names or ids. Therefore, I don’t really understand how it could possibly hurt accessibility to give an element a class name like "sidebar". The moment browsers or screen-readers care for class names, I will really think twice before picking a non-descriptive name, but I don’t think that moment is there yet. I’m not even sure if it would be a good idea for user-agents to care about that stuff. It would be like a Java compiler that throws an error if it doesn’t agree with the name of the interface you’re using.

Of course, when a page is completely redesigned by a new developer, it’s easier for him or her to work with names like "latest_news", "additional_information" and such, but making stuff easier to maintain shouldn’t be part of an accessibility law.

A bit too much?

I understand it fits in the whole semantics-paradigm and it feels like a natural thing to do, but maybe it’s a little extreme. Also, I don’t believe, especially when using Content Management Systems, that every piece of content can be predefined. When content managers can choose for themselves which content to put where, you could name every element on a page "additional_content" and it would all be semantically correct!

I would love to hear other arguments than "easier maintenance". If there really are good reasons, I will stand corrected and take it like a man.

Back to top

Filed under Accessibility, Industry and Culture

Comments:

  1. 08 February 2007 (09:11 AM) by Webby

    It's funny that you bring this up. It's one of the first rules you'll learn in coding. Give vars a readable name. Even better, add shortcuts before those names referring to their type. strSQLString, intTotalSum, etc.

    I presume that when we speak of government websites that they have multiple developers behind them and get revamped at least once a year by different company's maybe. The only reason still is easier maintenance as you mentioned, but why not.

    If you think it's crap stop using tab to indent also. Write your single line non descriptive xHTML like a man!

    this comment has been quoted by Harmen Janssen

  2. 08 February 2007 (10:25 AM) by Harmen Janssen

    Webby wrote:

    It's funny that you bring this up. It's one of the first rules you'll learn in coding. Give vars a readable name. Even better, add shortcuts before those names referring to their type. strSQLString, intTotalSum, etc.

    I presume that when we speak of government websites that they have multiple developers behind them and get revamped at least once a year by different company's maybe. The only reason still is easier maintenance as you mentioned, but why not.

    If you think it's crap stop using tab to indent also. Write your single line non descriptive xhtml like a man!

    Hehe, LOL :p

    You're right about that. I don't think it's crap though, I'm just skeptical about the accessible value of class names.

    I'm all for low maintenance! Just playing the devil's advocate here :)

Leave a comment

RE: Why use semantic class names?

Note to spammers: rel="nofollow" will be added to links. If I consider your comment spam, your IP-address might get blocked.

HTML not allowed. URLS will be auto-linked. Maximum length is 1250 characters.

I understand this is inconvenient, but the spam I'm receiving on this website is driving me nuts. Please forgive me and cope with it until I find a better solution.

Mandatory fields are marked by an asterisk (*).

Increase textarea-size Decrease textarea-size

Back to top

Preferences

These settings will be saved for your convenience.