CSS selectors cheat sheet

Selector Type Syntax Description
Universal Selector * Selects all elements
Element Selector p Selects all <p> elements
Class Selector .classname Selects all elements with class
ID Selector #idname Selects element with given id
Group Selector h1, h2, p Selects multiple element types
Descendant Selector div p Selects <p> inside <div>
Child Selector div p Selects direct children only
Adjacent Sibling Selector d h1 + p Selects <p> immediately after <h1>
General Sibling Selector h1 ~ p Selects all <p> after <h1>
Attribute Selector a[href] Selects <a> with href attribute
Pseudo-class a:hover Selects when hovering
Pseudo-element p::first-line Selects first line of <p>