What are child selectors in CSS?

The child selector uses the > sign and selects only the direct children of an element. The descendant selector (a space) selects children at any depth.

div > p { color: green; }   /* only p directly inside div */
div p   { color: red; }     /* every p inside div, at any depth */
<div>
  <p>Direct child</p>
  <section>
    <p>Not a direct child</p>
  </section>
</div>

Here div > p matches only the first paragraph. See CSS Selectors.


Learn more about the similar topics:
Tutorials
CSS Selectors
CSS Specificity
CSS Pseudo-classes and Pseudo-elements
Exercises & Assignments
No Content Found.
Interview Questions & Answers
What is the CSS class selector?
What is grouping in CSS and what is it used for?
What are child selectors in CSS?
What is the difference between id and class selector in CSS?
What is specificity in CSS?
What does !important do in CSS?
What are pseudo-classes and pseudo-elements in CSS?