CSS Descendant Selector

Descendant Selector

The Descendant selector in CSS is used to match the descendant components of a particular component. The term descendant depicts nested in whatever place, inside a DOM tree. This tree can be any direct children or deeper as compared to five levels, although it will be specified as the descendant.

A descendant combinator can be specified with the use of a single space. The descendant selectors links two selectors, where the first selector determines the ancestor. Here ancestor refers to parent’s parent and parent. The second selector is selected when it has the ancestor component, i.e., similar to any first selector. The descendant combinators in CSS can be used by the descendant selectors.


selector1 selector2
 /* property declaration */

Consider the below example:


<!DOCTYPE html>
 div p
  background-color: lime;
  font-weight: bold; 
 <p> It is the first paragraph inside the div. </p>
 <p> It is the second paragraph inside the div. </p>
 It is the second div inside the first div.
 <p> It is a paragraph inside the second div. This paragraph will also be affected. </p>
 <p> It is the paragraph four. This paragraph is not affected, because it is not inside any div. </p>


CSS Descendant Selector