:first-child
=
- first-child=
Summary
The :first-child pseudo-class matches an element that is the first child element of some other element.
Examples
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.
<style>
p:first-child { text-indent: 5px; }
</style>
The preceding selector would match the p inside the div of the first fragment that follows, but would not match the p in the second fragment.
<!-- 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>
Notes
Remarks
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>
Syntax
selector
- first-child
- selector
- A CSS simple selector.
Standards information
- CSS 2.1, Section 5.11.1
See also
Related articles
Pseudo-Classes
:first-child
Selectors
:first-child
Related pages
Reference
- first-letterfirst-letter
- first-linefirst-line
Attributions
Microsoft Developer Network: [Windows Internet Explorer API reference Article]