This page demonstrates various CSS selectors. View the source code to see how each selector works!
This paragraph is styled using the element selector p { }
All paragraphs on this page share basic styling.
This is a normal paragraph.
This paragraph has the "highlight" class applied!
Classes can be reused on any element.
The main title at the top uses #main-title - notice the green color and border.
IDs should be unique - only one element per ID per page!
We used h2, h3 { } to style them together.
This paragraph is inside .container (has blue left border)
This nested paragraph is also a descendant (also has border)
This paragraph is outside .container (no border)
I am a direct child of .direct-parent (red and bold)
I am nested inside a div, not a direct child (not red)
This paragraph comes immediately after h3 (purple, larger)
This paragraph is not adjacent to h3 (normal)
Hover over me to see the :hover effect!
| Selector Type | Example | Specificity |
|---|---|---|
| Element | p |
(0, 0, 1) |
| Class | .highlight |
(0, 1, 0) |
| ID | #main-title |
(1, 0, 0) |
| Combined | div.container p |
(0, 1, 2) |