CSS selectors A to Z

CSS selectors A to Z: 34 terms, each with what it does and a link to its full page.

Updated

A selector is the part of a CSS rule that says which elements the rule styles: p styles every paragraph, .intro every element with the class intro, nav a every link inside a nav.

Here is every CSS selector in the glossary, A to Z, with the pattern you type in the Syntax column. Pick a letter to jump down the list, or pick a selector to read its full page with an example.

TermSyntaxWhat it does
A
:activea:activeStyles an element while it is being pressed.
Adjacent sibling combinatorh2 + pThe + between selectors: matches the element right after another.
::after.price::afterAdds generated content at the end of an element.
Attribute selectorinput[type="email"]Selects elements by an attribute, written in [brackets].
B
::before.note::beforeAdds generated content at the start of an element.
C
:checkedinput:checkedStyles checkboxes and radio buttons that are selected.
Child combinatorul > liThe > between selectors: matches direct children only.
Class selector.introStarts with a dot and selects elements with that class.
CSS rulep { color: gray; }A selector plus a block of declarations: which elements, and how they look.
D
Descendant combinatornav aA space between selectors: matches elements anywhere inside another.
:disabledbutton:disabledStyles form controls that are switched off.
F
:first-childli:first-childSelects an element that is the first child of its parent.
:focusinput:focusStyles the element that has keyboard focus.
Functional pseudo-classli:not(.sold-out)A pseudo-class that takes selectors in brackets, like :not().
G
General sibling combinatorh2 ~ pThe ~ between selectors: matches every later sibling.
H
:has().card:has(img)Styles an element based on what it contains.
:hovera:hoverStyles an element while the mouse is over it.
I
ID selector#mainStarts with # and selects the one element with that id.
:is():is(h1, h2, h3)Matches any selector in its list.
L
:last-childli:last-childSelects an element that is the last child of its parent.
M
::markerli::markerStyles the bullet or number of a list item.
N
:not()button:not(.primary)Matches elements that don't match the selector inside.
:nth-child()tr:nth-child(even)Selects children by position, like odd rows or every third item.
P
::placeholderinput::placeholderStyles the hint text in an empty input.
Pseudo-classbutton:hoverStyles an element in a state, like :hover, with one colon.
Pseudo-elementp::first-lineStyles part of an element, or adds decoration, with two colons.
S
Selectornav a.activeThe part of a rule that picks which elements to style.
Selector listh1, h2, h3Several selectors separated by commas, sharing one set of styles.
Selector matchingBrowsers read selectors right to left: the last part first.
SpecificityHow precise a selector is; the more specific rule wins.
T
Type selectorpSelects every element with a given tag name, like p or img.
U
Universal selector*The * selector: matches every element.
V
:visiteda:visitedStyles links the user has already opened.
W
:where():where(ul, ol) liLike :is() but with zero specificity, so easy to override.

Every CSS term, by level