The Wayback Machine - https://web.archive.org/web/20230522000713/https://www.geeksforgeeks.org/what-is-first-child-in-css/
Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

What is first child in CSS ?

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The first-child is a pseudo-class in CSS that represents the first element among a group of sibling elements. The:first-child Selector is used to target the first-child element of its parent for styling.

Syntax:

:first-child {
     //property
}

Example: Here is the demonstration of the first child in CSS.

HTML




<!DOCTYPE html>
<html>
<head>
    <style>
        p:first-child {
            background: limegreen;
            color: white;
            font-style: italic;
            font-size: 1.875em;
        }
    </style>
</head>
<body>
    <p>I am first child.</p>
    <p>I am second child.</p>
    <p>I am third child.</p>
    <p>I am last child.</p>
</body>
</html>

Output:

My Personal Notes arrow_drop_up
Last Updated : 04 May, 2023
Like Article
Save Article
Similar Reads
Related Tutorials