Basic selectors
suggest change| Selector | Description |
|---|---|
* |
Universal selector (all elements) |
div |
Type selector (all <div> elements) |
.blue |
Class selector (all elements with class blue) |
.blue.red |
All elements with class blue and red (a compound selector) |
#headline |
ID selector (the element whose id is headline) |
:pseudo-class |
Elements that match a pseudo-class |
::pseudo-element |
Element that matches a pseudo-element |
:lang(en) |
Element that matches a language, for example <span lang="en"> |
div > p |
Child combinator: p elements whose parent is a div |
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.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents