Skip to content

CSS Tutorial CSS Selectors

CSS Descendant Selector

Lesson 13 of 182 2 min read By Deepak Paswan Updated Oct 4, 2026

A descendant selector is two selectors separated by a space. It matches the second one only when it sits somewhere inside the first, at any depth.

index.html
HTML
<style>
  nav a {
    color: #1a5276;
    text-decoration: none;
    margin-right: 12px;
  }
</style>
<nav>
  <a href="#">Home</a>
  <a href="#">Shop</a>
  <ul><li><a href="#">Nested link</a></li></ul>
</nav>
<p><a href="#">A link outside the nav</a></p>

nav a styles all links inside the nav, including the one in the nested list. The link in the paragraph is untouched.

Children, grandchildren and deeper

“Descendant” means any level below. In div p, the paragraph can be a child of the div, or inside a section inside an article inside the div.

You can chain more than two parts: .card ul li a means “a link in a list item in a list in a card”.

Don’t chain too far

Long selectors are fragile. If you change the HTML structure, the rule stops matching, and it becomes hard to override. Two parts are usually enough.

lightbulb
A good pattern
Give a container a class, and describe things inside it: .article-body img { max-width: 100%; }. The class marks where the rule applies, and the descendant part says what.

If you want only direct children and not deeper ones, see CSS Child Selector.