CSS descendant & child selectors
- type
- combinator
- applies to
- elements nested inside another selector
- inherits
- n/a
- common values
- nav a, nav > a, .card + .card
Where it goes
Whenever the same tag or class should look different depending on where it is on the page.
Example
nav a { color: white; } /* any <a> inside <nav>, any depth */
nav > a { color: white; } /* only <a> directly inside <nav> */Open this example in the editor →
Common mistakes
- Using a space when > was meant. The space version catches tags several levels deep, which can be more than you intended.
- Chaining many selectors, like nav ul li a span. It works, but it is fragile. Change the HTML slightly and the rule quietly stops matching.