CSS First Child Selector Last Updated : 12 Sep, 2024 Comments Improve Suggest changes Like Article Like Report CSS :first-child selector is used to select the elements that are the first child of the parent element. Syntax: :first-child { /* CSS property */ }Example 1: This example shows the use of the CSS first child selector. html <!DOCTYPE html> <html> <head> <title>first child selector</title> <style> h1 { color: green; } p:first-child { background-color: green; color: white; font-weight: bold; } body { text-align: center; } </style> </head> <body> <p>GeeksforGeeks</p> <h1>GeeksforGeeks</h1> <h2>:first-child Selector</h2> <p>GeeksforGeeks</p> <div> <p>GFG</p> <p>Geeks</p> </div> </body> </html> Output: Example 2: This example shows the use of the CSS first child selector. html <!DOCTYPE html> <html> <head> <title>first child selector</title> <style> h1 { color: green; } h1, h2 { text-align: center; } li:first-child { background: green; } body { width: 70%; } </style> </head> <body> <h1>GeeksforGeeks</h1> <h2>:first-child Selector</h2> <ul> <li>Data Structure</li> <li>Computer Network</li> <li>Operating System</li> </ul> <ol> <li>Java</li> <li>Ruby</li> <li>Pascal</li> </ol> </body> </html> Output: Supported Browsers: Apple Safari 3.1 and aboveGoogle Chrome 4.0 and aboveEdge 12.0 and aboveFirefox 3.0 and aboveOpera 9.5 and above Create Quiz Comment M manaschhabra2 Follow 0 Improve M manaschhabra2 Follow 0 Improve Article Tags : Misc Web Technologies CSS CSS-Selectors Explore CSS Introduction 3 min read CSS Syntax 3 min read CSS Selectors 6 min read CSS Comments 2 min read CSS Colors 5 min read CSS Borders 5 min read CSS Margins 4 min read CSS Height and Width 4 min read CSS Outline 4 min read CSS Fonts 4 min read Like