CSS Child Selector


Use the child selector, if you want to select all elements immediate children of a specified element.

div > p

Example

You can try to run the following code to implement CSS Child Selector

Live Demo

<!DOCTYPE html>
<html>
   <head>
      <style>
         div > p {
            background-color: orange;
         }
      </style>
   </head>
   <body>
      <div>
         <p>Para 1 in the div.</p>
         <!-- This is not a Child -->
         <span><p>Para 2 in the div.</p></span>
      </div>
      <p>Para 3 outside the div.</p>
   </body>
</html>

Output

Updated on: 30-Jun-2020

264 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements