WeCodeAcademy

CSS Selectors

Selectors choose which elements a rule applies to.

31 of 31
NameDescription
.classSelects elements with a class.
#idSelects the element with an id.
*Selects every element.
elementSelects all elements of a type.
element, elementSelects all listed elements.
element elementSelects descendants.
element > elementSelects direct children.
element + elementSelects the next sibling.
element ~ elementSelects following siblings.
[attribute]Selects elements that have an attribute.
[attribute=value]Selects elements with an exact attribute value.
[attribute^=value]Attribute starts with value.
[attribute$=value]Attribute ends with value.
:hoverSelects an element under the mouse.
:focusSelects the focused element.
:activeSelects an element being pressed.
:first-childSelects the first child of its parent.
:last-childSelects the last child.
:nth-child(n)Selects children by position.
:not(selector)Selects elements that do not match.
:checkedSelects checked inputs.
:disabledSelects disabled controls.
:rootSelects the document root (html).
:is(a, b)Matches any selector in the list.
:has(selector)Selects an element that contains a match.
::beforeInserts content before an element.
::afterInserts content after an element.
::first-letterStyles the first letter.
::first-lineStyles the first line.
::selectionStyles selected text.
::placeholderStyles placeholder text.