Stylin’ with CSS

The Blog and Books of Charles Wyke-Smith

CSS Selectors Reference List

Basic and Contextual Selectors
Pattern Meaning Described in Section
* Any element Universal selector
E An element of type E Type selector
E F An F element descendant of an E element Descendant combinator
E > F An F element child of an E element Child combinator
E + F An F element immediately preceded by an E element Adjacent sibling combinator
E ~ F An F element preceded by an E element General sibling combinator
Back to Top  
ID and Class
Pattern Meaning Described in Section
E#myid An E element with ID equal to “myid” ID selectors
E.warning An E element whose class is “warning” (the document language specifies how class is determined) Class selectors
Back to Top  
Attribute Selectors
Pattern Meaning Described in Section
E[foo] An E element with a “foo” attribute Attribute selectors
E[foo="bar"] An E element whose “foo” attribute value is exactly equal to “bar” Attribute selectors
E[foo~="bar"] An E element whose “foo” attribute value is a list of whitespace-separated values, one of which is exactly equal to “bar” Attribute selectors
E[foo^="bar"] An E element whose “foo” attribute value begins exactly with the string “bar” Attribute selectors
E[foo$="bar"] An E element whose “foo” attribute value ends exactly with the string “bar” Attribute selectors
E[foo*="bar"] An E element whose “foo” attribute value contains the substring “bar” Attribute selectors
E[foo|="en"] An E element whose “foo” attribute has a hyphen-separated list of values beginning (from the left) with “en” Attribute selectors
Back to Top  
Structural Pseudo-Classes
Pattern Meaning Described in Section
E:root An E element, root of the document Structural pseudo-classes
E:nth-child(n) An E element, the n-th child of its parent Structural pseudo-classes
E:nth-last-child(n) An E element, the n-th child of its parent, counting from the last one Structural pseudo-classes
E:nth-of-type(n) An E element, the n-th sibling of its type Structural pseudo-classes
E:nth-last-of-type(n) An E element, the n-th sibling of its type, counting from the last one Structural pseudo-classes
E:first-child An E element, first child of its parent Structural pseudo-classes
E:last-child An E element, last child of its parent Structural pseudo-classes
E:first-of-type An E element, first sibling of its type Structural pseudo-classes
E:last-of-type An E element, last sibling of its type Structural pseudo-classes
E:only-child An E element, only child of its parent Structural pseudo-classes
E:only-of-type An E element, only sibling of its type Structural pseudo-classes
E:empty An E element that has no children (including text nodes) Structural pseudo-classes
E:root An E element, root of the document Structural pseudo-classes
E:not(s) An E element that does not match simple selector s Negation pseudo-classes
Back to Top  
UI Pseudo-Classes
Pattern Meaning Described in Section
E:linkE:visited An E element being the source anchor of a hyperlink of which the target is not yet visited (:link) or already visited (:visited) The link pseudo-classes
E:activeE:hoverE:focus An E element during certain user actions The user action pseudo-classes
E:target An E element being the target of the referring URI The target pseudo-class
E:lang(fr) An element of type E in language "fr" (the document language specifies how language is determined) The :lang() pseudo-classes
E:enabled A user interface element E which is enabled or disabled The UI element states pseudo-classes
E:disabledE:checked A user interface element E which is checkedĀ (for instance a radio-button or checkbox) The UI element states pseudo-classes
Back to Top  
Pseudo-Elements
Pattern Meaning Described in Section
E::first-line The first formatted line of an E element The ::first-line pseudo-element
E::first-letter The first formatted letter of an E element The ::first-letter pseudo-element
E::before Generated content before an E element The ::before pseudo-element
E::after Generated content after an E element The ::after pseudo-element
Back to Top