CSS Basic selectors


Example

SelectorDescription
*Universal selector (all elements)
divTag selector (all <div> elements)
.blueClass selector (all elements with class blue)
.blue.redAll elements with class blue and red (a type of Compound selector)
#headlineID selector (the element with "id" attribute set to headline)
:pseudo-classAll elements with pseudo-class
::pseudo-elementElement that matches pseudo-element
:lang(en)Element that matches :lang declaration, for example <span lang="en">
div > pchild selector

Note: The value of an ID must be unique in a web page. It is a violation of the HTML standard to use the value of an ID more than once in the same document tree.

A complete list of selectors can be found in the CSS Selectors Level 3 specification.