Selectors
Reference
Read The Cascade from Web.dev
Basic selectors:
Element selector (
p) targets all paragraphsClass selector (
.classname) targets elements with that classID selector (
#idname) targets the unique element with that IDUniversal selector (
*) targets all elements
Combinators:
Descendant (
div p) targets paragraphs inside divsChild (
div > p) targets direct children onlyAdjacent sibling (
h1 + p) targets the first paragraph immediately after an h1General sibling (
h1 ~ p) targets all following sibling paragraphs
Attribute selectors:
[attribute]targets elements with that attribute[attribute="value"]targets exact matches[attribute^="value"]starts with[attribute$="value"]ends with[attribute*="value"]contains
Pseudo-classes target elements in specific states:
:hover,:focus,:activefor user interactions:first-child,:last-child,:nth-child(n)for position:not()for exclusions
Pseudo-elements style parts of elements:
::before,::afterfor generated content::first-line,::first-letterfor text styling
Last updated
