CSS Selectors Cheat Sheet

A quick reference for common CSS selectors.

SelectorDescription
*Selects all elements.
.classSelects all elements with a specific class.
#idSelects an element with a specific ID.
elementSelects all elements with a specific tag name.

SelectorDescription
element elementSelects all `<element>` inside another `<element>`.
element > elementSelects all `<element>` where the parent is a specific `<element>`.
element + elementSelects all `<element>` that are placed immediately after another `<element>`.
element1 ~ element2Selects every `<element2>` that are preceded by an `<element1>`.

SelectorDescription
:hoverSelects elements on mouse over.
:first-childSelects the first element among a group of siblings.
:last-childSelects the last element among a group of siblings.
:nth-child(n)Selects the nth element among a group of siblings.