May 21

The Symptoms

Ignoring HTML elements such as h1, h2, ul, li, and instead styling all text with classes applied to divs and spans. e.g.:

HTML:
  1. <div class="list">
  2. <span class="heading" style="font-size:12px; font-weight:bold;">
  3.    My Items
  4. </span>
  5. <br />
  6.       • <span style="font-size:10px;">Item 1</span><br />
  7.       • <span style="font-size:10px;">Item 2</span><br />
  8.       • <span style="font-size:10px;">Item 3</span>
  9. </div>

Which displays as this:

My Items

Item 1
Item 2
Item 3

The Diagnosis

A case of divitus and/or spanitus.

The Antidote

Use HTML elements and then use CSS to style them.

HTML:
  1. <div class="nav">
  2. <h2>My Navigation Description</h2>
  3.    <li>Navigation Item 1</li>
  4.    <li>Navigation Item 2</li>
  5.    <li>Navigation Item 3</li>
  6. </ul>
  7. </div>

CSS:
  1. .nav ul li{
  2.    font-size: 10px;
  3. }
  4. .nav h2{
  5.    font-weight: bold;
  6.    font-size: 12px;
  7. }

Why Cure This?

There are many reasons:

  1. Accessibility.

    Using HTML elements for headings, lists, and everything else increases the accessibility of your site to users who may not interact with the World Wide Web in the same way that you do. Faulkner at Fadtastic notes that disabled users account for £50 million (USD$98,780,000 at time of writing) of the 2005 market share in the UK alone. Include those people!

  2. Code Readability.

    If anyone, and I mean anyone from developer to casual web nut, looks at your source, they will get a basic idea of the structure of your site. This is especially important if you are passing off your work to another developer.

  3. SEO.

    Search engines place heavy weight on sites that have pertinent keywords within h1 and h2 tags. The 15 minute SEO checklist (thanks, Daniel) also shows negative points are given to poorly coded sites - yes, that means those suffering from divitus and spanitus, you know who you are.

  4. Cross-Media Support.

    With the advent of pocket devices, mobile phones, and gaming systems with browsers, not everyone may support CSS or be able to view your site in the same way as you intended for the screen. Using proper HTML elements, you allow the devices to override the stylesheet if necessary and interpret your document more accurately. Opera's site offers a checklist of additional quick tips to make sites look great on small devices.

I'm sure there are myriads of other reasons to use HTML elements rather than spans and divs. Do you have any to add? Leave a comment and let me know.

Popularity: 5% [?]

Share and Enjoy:
  • del.icio.us
  • Digg
  • Reddit
  • TwitThis
  • Google Bookmarks
  • StumbleUpon
  • Facebook
  • E-mail this story to a friend!
  • Print this article!

2 Responses to “Use HTML elements”

  1. Greg King Says:

    This is always a good point to stress. Many people when they finally "get" CSS go too far and want to do everything as divs and spans. Do not reinvent the wheel, use whatever tag the best matches the structural intent of your code.

  2. Jennifer Says:

    You're right, Greg. Maybe if we cry out with enough voices, they will hear us. Your blog name this issue perfectly - "A Div Too Far" - how true that sometimes can be.

Leave a Reply




  • Meta