← CSS Styling
CSS foundations · 15 MIN

Selectors and combinators

Selectors and combinators

Type, class, ID, attribute and pseudo-class selectors target elements. Descendant and child combinators express relationships. Prefer reusable classes over long, fragile selector chains and avoid unnecessary ID selectors for styling.

Try it yourself

Change the example, run it, and explain the result in your own words. Then create one variation of your own.

Key idea

Use the example as a starting point, not something to memorize. Practise, inspect the result and make small improvements.

Code example

.card { padding: 1rem; }
.card h2 { margin-top: 0; }
nav > a { text-decoration: none; }