Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All


Applies one or more styles to any element that is the first child of its parent.


:first-child { sRules }

Possible values


Value that specifies one or more cascading style sheets attribute/value pairs.


The :first-child pseudo-class matches an element that is the first child element of some other element.

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 code:

<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 suppresses indentation for the first paragraph only):

    p:first-child {text-indent: 0}

The preceding selector would match the P element inside the DIV of the first fragment that follows, but would not match the P element in the second fragment:

<!-- First fragment -->
<div class="note">
   <p> The first P inside the note. </p>
<!-- Second fragment -->
<div class="note">
   <p> The first P inside the note. </p>

Applies to

a, abbr, acronym, address, b, big, blockquote, body, caption, center, cite, code, col, colgroup, dd, dfn, dir, div, dl, dt, em, form, hn, html, i, img, input, input type=button, input type=checkbox, input type=file, input type=hidden, input type=image, input type=password, input type=radio, input type=reset, input type=submit, input type=text, kbd, label, legend, li, listing, marquee, menu, ol, p, plaintext, pre, s, samp, select, small, span, strike, strong, sub, sup, table, tbody, td, textarea, tfoot, th, thead, tr, tt, u, ul, var, xmp

See also

Send feedback about this topic to Microsoft. © 2011 Microsoft Corporation. All rights reserved.

Community Additions

© 2015 Microsoft