In this exercise, you will practice using CSS selectors to style specific elements on a page.
You can experiment with different selectors in the code editor on the left. The preview on the right will update to show your changes when you click "Apply".
Below the playground, you'll find challenges to test your knowledge of CSS selectors.
This is a paragraph with some special text.
This paragraph has a unique ID.
Paragraph inside a div
Another paragraph with a link inside.
| Selector | Example | Description |
|---|---|---|
| Element | p { } |
Selects all paragraph elements |
| Class | .special { } |
Selects all elements with class="special" |
| ID | #unique { } |
Selects the element with id="unique" |
| Descendant | div p { } |
Selects all <p> elements inside <div> elements |
| Child | div > p { } |
Selects all <p> elements that are direct children of a <div> element |
| Pseudo-class | a:hover { } |
Selects links when mouse hovers over them |
| Pseudo-element | p::first-line { } |
Selects the first line of all <p> elements |
| Adjacent Sibling | h1 + p { } |
Selects <p> elements that directly follow an <h1> |