# Combinators {{PreviousMenuNext("Learn_web_development/Core/Styling_basics/Pseudo_classes_and_elements", "Learn_web_development/Core/Styling_basics/Test_your_skills/Selectors", "Learn_web_development/Core/Styling_basics")}} The final selectors we will look at are called combinators. Combinators are used to combine other selectors in a way that allows us to select elements based on their location in the DOM relative to other elements (for example, child or sibling).
Prerequisites: HTML basics (study Basic HTML syntax), Basic CSS selectors.
Learning outcomes:
  • The basic concept of combinators.
  • Descendant and child combinators.
  • Next- and subsequent-sibling combinators.
  • Nesting.
  • Combining combinators with selectors.
## Descendant combinator The **descendant combinator** — represented by a single space ( ) character — combines two selectors such that elements matched by the second selector are selected if they have an ancestor (a parent, a parent's parent, or a parent's parent's parent, etc.) element matching the first selector. Selectors that utilize a descendant combinator are called _descendant selectors_. ```css body article p { } ``` In the example below, we are matching only the `

` element which is inside an element with a class of `.box`. ```html live-sample___descendant

Text in .box

Text not in .box

``` ```css live-sample___descendant .box p { color: red; } ``` {{EmbedLiveSample("descendant")}} > [!NOTE] > [Aside: Compound selectors](https://scrimba.com/frontend-path-c0j/~0br?via=mdn) [_MDN learning partner_](/en-US/docs/MDN/Writing_guidelines/Learning_content#partner_links_and_embeds) from Scrimba is an interactive lesson providing a practical treatment of descendant combinators. ## Child combinator The **child combinator** (`>`) is placed between two CSS selectors. It matches only those elements matched by the second selector that are the direct children of elements matched by the first. Descendant elements further down the hierarchy don't match. For example, to select only `

` elements that are direct children of `

` elements: ```css article > p { /* … */ } ``` In this next example, we have an ordered list ({{htmlelement("ol")}}) nested inside an unordered list ({{htmlelement("ul")}}). The child combinator selects only those `
  • ` elements which are direct children of a `