The blog is all about my life, my work, and giving back to the web development community I learn so much from every day!

Markup Conventions

While hardly earth shattering, one useful XHTML convention I’ve been using lately is to always make the id attribute the first on a tag, and make the class attribute the last. The most common case that I need both attributes is for input tags (and usually because IE 6 doesn’t support attribute-selectors), for example:


<input id="first-name" name="first-name" type="text" classic="text" />

Using this convention also means I can place the id and the name adjacent to each other – also handy. While this may not be the preferred convention for everyone, I find it’s just one more thing that helps me read that code in 6 months time – if I stick to it, it’s pretty quick for my eye to scan to that all-important information.

5 Responses to this entry so far…

Care to share your thoughts?

  1. You know – I do exactly the same thing myself.

    Another thing I do is to name any associated background images the same as their ID. So Title might have a background image named h1-bg-the-title.gif.

    Works for me. ;)

  2. Top idea. Ya know, come to think of it, I do the same thing, but on some weird subconscious level. I’ve just always done it, but never knew why (probably for same “id near the name” reason as you). Now I’m thinking about it though, I’ll be sure to keep on doing it. :)

Share your thoughts on this entry