CSS {selectors: reference}
Basic
Universal
*
selects all elements
Type
div
selects all elements of that type
Class
.c
selects all elements of that class
Id
#i
selects all elements of that id
Combinator
Descendant
div a
selects specified elements that are descendants of the first element
Direct Child
div > a
selects elements that are direct children of the first element
General Sibling
div ~ a
selects elements directly after the specified element
Adjacent Sibling
div + a
selects elements that are siblings of specified element and come directly after the specified element
Or
div, a
selects elements that match any element in the list
And
div.c
selects elements that match all the selector combinations
Attribute
Has
[a]
selects elements that have that attribute
Exact
[a='1']
selects elements that have that attribute with exactly that value
Begins With
[a^='1']
selects elements that have that attribute which starts with that value
Ends With
[a$='1']
selects elements that have that attribute which end with that value
Substring
[a*='1']
Selects elements that have that attribute which contain that value anywhere
Pseudo Element
Before
div::before
creates an empty element directly before the children of the selected element
After
div::after
creates an empty element directly after the children of the selected element
Pseudo Element (State)
Hover
button:hover
selects elements that are hoverable by the mouse
Focus
button:focus
selects elements that are being focused
Required
input:required
selects elements that have the required attribute
Checked
input:checked
selects checkboxes and radio buttons that are checked
Disabled
input:disabled
selects inputs that have the disabled attribute
Pseudo Element (Position / Other)
First Child
a:first-child
selects the first child of the specified element's parent
Last Child
a:last-child
selects the last child of the specified element's parent
Nth Child
a:nth-child(2n)
selects the specified element according to paramater (not zero based) given. For example, (2n) selects every other element
Nth Last Child
a:nth-last-child(3)
selects the specified element according to paramater (not zero based) given, counting from the end
Only Child
a:only-child
selects elements that are the only child inside a container
First of Type
a:first-of-type
selects elements that are the first of a type inside a container
Last of Type
a:last-of-type
selects elements that are the last of a type inside a container
Nth of Type
a:nth-of-type(2)
selects elements that are the nth of a type inside a container, based on the paramater given to it
Only of Type
a:only-of-type
similar to only-child, but selects elements if they are the only type of that element inside a container
Not
a:not(.c)
selects all elements that are not the specified element