Role of CSS: first-child Selector

Use the CSS :first-child selector to style every

elements that is the first child of its parent.

Example

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


   
      
   
   
      

Heading

     

This is demo text.

     
         

This is demo text, with the first child of its parent div.

         

This is demo text, but not the first child.

     
   
Updated on: 2026-03-11T22:50:41+05:30

224 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements