CSS :first-childSelectors

Complete CSS Selector Reference Manual

Example

Matches the first <p> element of its parent element.

p:first-child { background-color:yellow; }

Try it Yourself »

Definition and Usage

The :first-child selector matches the first child element of its parent element.


Browser Support

The numbers in the table indicate the first browser version that supports the property.

Selectors
:first-child 4.0 7.0 3.0 3.1 9.6

Note:In IE8 and earlier versions of IE, a DOCTYPE must be declared for :first-child.<!DOCTYPE>


Related Articles

CSS Tutorial:CSS Pseudo-classes


Examples

More Examples


Example

Select and style every <i> element inside every <p> that is the first child of its parent:

p:first-child i { background:yellow; }

Try it Yourself »

Example

The style selected for the first <li> element in the list:

li:first-child { background:yellow; }

Try it Yourself »

Example

The style selected for the first child element of each <ul> element:

ul>:first-child { background:yellow; }

Try it Yourself »


Complete CSS Selector Reference Manual

other extensions