Back to Cheat Sheets
Cheat Sheets/CSS Selectors Reference
css

CSS Selectors Reference

Complete CSS selector patterns

CSSSelectorsReference
Basic Selectors
Universal
*

Select all elements

Element
div

Select by tag name

Class
.className

Select by class

ID
#id

Select by ID

Attribute
[type="text"]

Select by attribute

Combinators
Descendant
div p

All p inside div

Child
div > p

Direct child p of div

Sibling
div + p

p immediately after div

General sibling
div ~ p

All p after div

Pseudo-Classes
:hover
a:hover

When mouse is over element

:focus
input:focus

When element has focus

:nth-child
li:nth-child(2n)

Every even li

:first-child
p:first-child

First child of parent

:not()
p:not(.special)

Elements not matching