Role of CSS: first-child Selector

Use the CSS :first-child selector to style every <p> elements that is the first child of its parent.


You can try to run the following code to implement the :first-child selector

Live Demo

<!DOCTYPE html>
         p:first-child {
            background-color: orange;
      <p>This is demo text.</p>
         <p>This is demo text, with the first child of its parent div.</p>
         <p>This is demo text, but not the first child.</p>