Easy Tutorial
❮ Pr Border Righ Pr Print Pagebb ❯

CSS :first-child Selector

Complete CSS Selectors Reference

Example

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

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

Definition and Usage

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


Browser Support

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

Selector
:first-child 4.0 7.0 3.0 3.1 9.6

Note: The :first-child selector must be declared with <!DOCTYPE> in IE8 and earlier versions of IE.


Related Articles

CSS Tutorial: CSS Pseudo-classes


More Examples

Example

Selects and styles each <i> element within <p> elements, where the <p> element is the first child of its parent:

Example

Styles the first <li> element in a list:

li:first-child
{
    background: yellow;
}

Example

Styles the first child element of every <ul> element:

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

Complete CSS Selectors Reference

❮ Pr Border Righ Pr Print Pagebb ❯