Applies one or more styles to any element that is the first child of its parent.
A CSS simple selector.
- CSS 2.1, Section 5.11.1
The :first-child pseudo-class matches an element that is the first child element of some other element.
Note Requires Windows Internet Explorer 7 or later.
Note Pseudo-class enabled only in standards-compliant mode (strict !DOCTYPE).
Inline text is not considered to be part of the document tree, and is not counted when calculating the first child. For example, the EM element is the first child of the p element in the following HTML.
<p>abc <em>default</em> def</p>
In the following example, the selector matches any p element that is the first child of its parent. The style rule below applies indentation to the p of the First fragment only.
<!-- First fragment --> <div class="note"> <p> The first P inside the note. </p> </div> <!-- Second fragment --> <div class="note"> <h2>Note</h2> <p> The first P inside the note. </p> </div>