Descendant combinator (space)
ancestor descendant
Two selectors separated by a space select elements matching the second selector that lie anywhere inside an element matching the first one – as children, grandchildren or deeper. The specificities of both parts add up (.article a has 0-1-1).
Examples
Links in the menu and in the article look different, even though they are the same a elements:
<nav class="menu"><a href="#">Home</a> <a href="#">Contact</a></nav> <div class="article"><p>Text with a <a href="#">link</a> in an article.</p></div>
.menu {
padding: 6px 10px;
background: #01579b;
}
.menu a {
color: #fff;
text-decoration: none;
}
.article p { margin: 8px 0 0; }
.article a { color: #0088d1; }
The space selects at any depth – the items of the nested list get the blue line too:
<ul class="menu">
<li>Products
<ul>
<li>Bikes</li>
<li>Helmets</li>
</ul>
</li>
<li>Contact</li>
</ul>
.menu,
.menu ul {
margin: 0;
padding-left: 16px;
list-style: none;
}
.menu li {
margin: 4px 0;
padding-left: 6px;
border-left: 3px solid #0088d1;
}
Only the first-level items would be selected by the child combinator .menu > li.
Things to watch out for
- The space selects at any depth – a rule for
.menu lialso hits the items of nested submenus. Only direct children are selected by.menu > li. - A space in a selector has a meaning:
.a .b(an element.binside.a) is not the same as.a.b(an element with both classes). - The ancestor is searched up to the root of the document:
div palso selects a paragraph in asectionif there is somediva few levels higher. - Long chains (
body .page .content .article p a) increase specificity and tie the CSS to the structure of the HTML; after a change of the HTML they stop applying. Two levels or a class are usually enough.
Browser support
Baseline – widely available: works in all major browsers and has for a long time (since 2015 at the latest). Since version: Chrome 1, Firefox 1, Safari 1. As of October 2026 (MDN browser-compat-data).
Related:
Child combinator (>)
Next-sibling combinator (+)
Class selector (.class)
Specificity and the cascade