You are here:
- Manual
- Development
- Descriptive markup
- Writing
Classandidattributes
Descriptive markup: Descriptive names for class and id attributes
The HTML attributes class and id can be used to mark elements, so that they can easily be used for manipulating CSS (Cascading Style Sheets). Likewise, a descriptive name can be given to an otherwise generic element (example: linking to it.).
Give meaningful names to id and class attributes.
Guideline R-pd.3.15
Example of a class attribute on an element (HTML)
<em class="warning">Be aware!</em>
Through CSS, this element can be styled differently from other em elements on the page, due to the class on the <em> tag. Web developers should use meaningful names for class and id attributes.
Example of inappropriate use (HTML)
<a class="small"...>
Example of appropriate use (HTML)
<a class="footnote" ...>
The use of names to describe appearance rather than function has several disadvantages.
- No separation of structure from content. The appearance of the element is described in the structure, while the very idea is to separate the two. When the CSS for the footnote link is changed and it no longer looks small, the class "small" has lost its meaning. It may even cause confusion when the site is changed or expanded.
- Complication of the expandability of the site. When the web developer or content manager expanding the site wants to use a footnote link, (s)he has to remember that the corresponding class is "small". A link with class "footnote" is more logical and easier to remember.
Good names don't change
