Classes and ids

From CSS Standards FAQ

Jump to: navigation, search

Classes and ids are a way of selecting which elements in a document a CSS rule should apply to. The diffrence between classes and ids should be obvious from the name, but since many asks and actually use them wrong, it will be covered here.

Ids are used to select only one element in a document and only one element can have a id name. In a CSS selector id names has a hash(#) prefix. Classes are used to select a collection of elements and can be used on as many elements desirable. Classes names is prefixed with a dot in css selectors. Allthough you could choose to use only classes, it is recommended that you use ids when appropriate as they make it possible to link to a specific part of a document and can also be used in javascript and XSLT. They also have a higher specificity.

Further reading

Personal tools