Question

What is the benefit of writing meaningful css .class and #id names? Do screen readers speak to help the user understand the meaning and purpose of content inside the tags?

Was it helpful?

Solution

Again, as all your recent questions on semantics, the answer stays the same:

It all depends on the data-context of the entity in question.

If your element holds a meaningful field, it is useful to assign it a class (even if you do not want to apply CSS to it) just to easily define that particular field:

<span class="username">Andrew Moore</span>

Doing so has the following advantages:

  • It easily identifies the field's content in your code.
  • It increases maintainability.
  • It helps parsers and third-party applications to fetch this field's value.

Microformats are just a larger example of this. Simply put, they are a set of pre-defined elements and attributes that hold a particular set of data, meant to ease parsing by third-party tools.

OTHER TIPS

Generally-speaking, it's beneficial for the developer/designer only.

Other answers are good, but I will focus on the scraping/third party tools aspect here.

Case 1 is spiders and crawling like search engines. If they parse your page and see something like id="username", they will be more likely to figure out some meaning in that than id="div-style-32". Granted, I'm not sure Google is doing this sort of thing now, but it could be if more people were better about it.

Case 2 is people writing scripts to pull down the HTML and process it in order to extract its content as data. Pretty much anyone who wants to do this can with any markup, its just a matter of how annoying it is. Cleaner and more well described markup allows the scraper script to more easily find the information it needs due to it's increased semantics.

This also includes things like browser extensions or Greasemonkey scripts that allow users to alter the behavior of the site. It will be easier to create these modifications with cleaner markup.

But if you don't want people scraping or modifying your site with client side extension, there is little you can do about from a technical standpoint. You can't stop it, you can only make it more of a pain in the ass. And the benefits of maintainability for the site developers are huge. So really, why not?

In short it makes all the different things you or others could do with your site easier to do.

You don't do it for the machines but for the humans.

If we only cared about machines we'd still be coding in assembly :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top