Little Web Hut
(Cascading Style Sheets) CSS 2.1 Reference

CSS Pseudo-class :first-child Selector

 

What is a CSS Pseudo-class :first-child Selector?

  • The :first-child pseudo-class selector specifies an element that is the first child of another element. In the following example, the color property will be set to red for any <p> element that is the first child of the <div> element. The style is NOT applied to the second <p> element since it is the second child.
CSS Example:
  p:first-child {color: red;}
  <div>
    <p>The red style has been applied to this element.</p>
    <p>The red style has not been applied to this element.</p>
  </div>
Test It HTML StyleTest It XHTML StyleTest It HTML5 Style