Little Web Hut
(Cascading Style Sheets) CSS 2.1 Reference

CSS Child Selector

 

What is a CSS Child Selector?

  • The child selector specifies an element that is a child of another element. The syntax is two or more selectors separated by right angle brackets (>). The child selector is listed last. In the following example, the color property will be set to red for all <strong> elements that are children of <div> elements. Therefore, the first <strong> element will receive the style because it is a child of a <div> element. The second <strong> element will not receive the style because, even though it is a descendant of a <div> element, it is not a child of a <div> element.
CSS Example:
  div > strong {color: red;}
  <div>The red style <strong>has been applied to this element.</strong></div>
  <div><p>The red style <strong>has not been applied to this element.</strong></p></div>
Test It HTML StyleTest It XHTML StyleTest It HTML5 Style