This page is Not Ready

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

: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
### Parameters
selector
A CSS simple selector.

Standards information

See also

Related articles

Pseudo-Classes

Selectors

Related pages

Attributions