CSS Descendant Combinator

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The descendant combinator is whitespace (usually a space) between two selectors. It matches elements selected by the second selector that have an ancestor matching the first — at any depth.

Example: .box p styles every p inside .box, including nested ones. Prefer the child combinator (>) when you need only direct children. Read selectors right to left: the rightmost part is what you style.

Baseline · Widely available.

Not deprecated. Core CSS since CSS1. Extremely broad support across browsers.

CSS Syntax

syntax.css
ancestor   descendant { /* declarations */ }

The combinator is whitespace (usually one space) between the two selectors. Examples: nav a · .box p · li li · div span

Selector Forms

PatternMatchesTry it
nav aLinks nested inside a navTry it
.box pParagraphs scoped to a classed containerTry it
li liList items nested inside other list itemsTry it
vs div > pChild combinator — direct children onlyTry it

How to Use the Descendant Combinator

Name the ancestor, leave a space, then name what you want to style.

  1. Choose the ancestor (element, class, or id).
  2. Add a space (the combinator).
  3. Choose the descendant to style.
  4. Prefer a scoped ancestor (e.g. .card p) over a bare type when possible.
PieceRequired?Role
Ancestor selectorYesLimits the search tree
WhitespaceYesThe descendant combinator
Descendant selectorYesWhat actually receives the styles
Depth—Any nesting level matches

Live Preview

Switch between .demo p (all nested paragraphs) and .demo > p (direct children only). Highlighted text shows what matches.

Blue highlight = matched. Nested paragraph only matches the descendant combinator.

Tree

Direct child paragraph

Nested paragraph (deeper)

.demo p — both paragraphs match

CSS Examples

Each snippet focuses on the descendant space combinator. Use Try It Yourself for a live editor.

Example 1 — Scope Paragraphs to a Box

Style only paragraphs inside a container.

CSS
<style>
  .box p {
    color: #dc2626;
  }
</style>

<div class="box">
  <p>Inside the box</p>
</div>
<p>Outside the box</p>
Try It Yourself

How It Works

  1. Ancestor: .box limits where we look.
  2. Space combinator: means “any descendant.”
  3. Target: p elements get the red color.
  4. Outside stays default. The sibling paragraph is not under .box.

Example 2 — Nested List Markers

Style list items that sit inside other list items.

CSS
<style>
  li {
    list-style-type: disc;
  }

  li li {
    list-style-type: circle;
  }
</style>

<ul>
  <li>Item
    <ul>
      <li>Subitem</li>
    </ul>
  </li>
</ul>
Try It Yourself

How It Works

  1. Base rule. All li use disc bullets.
  2. Descendant rule. li li means an li inside another li.
  3. Any depth. Nested sublists still match.
  4. Outer stays disc. Only nested items switch to circle.

Example 3 — Links Inside Nav

Style anchors only when they live under navigation.

CSS
<style>
  nav a {
    color: #1d4ed8;
    text-decoration: none;
    font-weight: 600;
  }
</style>

<nav>
  <a href="#">Home</a>
  <a href="#">Docs</a>
</nav>
<p><a href="#">Footer link</a></p>
Try It Yourself

How It Works

  1. Ancestor: nav scopes the rule.
  2. Space + a. Any link under that nav matches.
  3. Footer stays default. Its link is not a descendant of nav.
  4. Safer than bare a. Avoids restyling every link on the page.

Edge Cases & Pitfalls

If too many elements light up, check these first.

vs >

Space ≠ child combinator

div p matches deep nests. div > p matches only direct children. Use > when depth must be exact.

scope

Broad ancestors over-match

div span can hit far more than you intend. Prefer a classed container like .card span.

compound

No space in compound selectors

a.button (no space) is one element with both conditions. a .button (space) is a descendant with class button.

specificity

Each simple selector adds specificity

.nav a is more specific than bare a. Long chains can become hard to override — keep them short.

read

Read right to left

The browser finds candidates for the rightmost selector, then checks ancestors. Mentally: “style these, but only under that.”

Browser Support

The descendant combinator is a browser CSS selector. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

descendant combinator

Supported everywhere CSS is supported (CSS1-era). Safe for all teaching and production use.

100% Core support
Google Chrome 1+
Full support
Mozilla Firefox 1+
Full support
Apple Safari 1+
Full support
Microsoft Edge 12+
Full support
Opera 3.5+
Full support
Samsung Internet 1+
Full support
Internet Explorer 3+
Full support
ancestor descendant Universal

Bottom line: No prefixes. No polyfills. It is not a runtime API.

Key Takeaways

  • Role: match nested elements under an ancestor at any depth.
  • Syntax: whitespace between selectors (usually a space).
  • vs >: descendant = any depth; child = one level only.
  • Tip: scope with a classed ancestor to avoid over-matching.

One line: a space means “somewhere inside” — style the right side, limited by the left ancestor.

Frequently Asked Questions

A space between two selectors matches elements selected by the second selector that have any ancestor matching the first — child, grandchild, or deeper.
The space (descendant) matches at any nesting depth. The > child combinator matches only direct children one level down.
Put whitespace between selectors: div p, .article li, or nav a. The right-hand side is what gets styled.
It limits styles to a section of the page so you do not restyle every p on the site by accident.
Yes. It has been in CSS since CSS1 and is Baseline Widely available in every modern browser. It is a selector combinator, not a Node.js feature.
Yes. The combinator is one or more CSS whitespace characters and may include CSS comments between the selectors.

Next: grouping

Learn how comma-separated selector lists share the same declarations.

grouping tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful