:first-child

:first-child – pseudo-class | Selectors Level 3

The :first-child  selects any element that is the first child of its parent element.

Syntax

element:first-child {
    style properties
}

Example

<ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
</ul>
<ul>
    <li>4</li>
    <li>5</li>
    <li>6</li>
</ul>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
li:first-child {
    background:#FFB7C5;
}

Every li element that is the first child of its parent will be selected.

Related

Resources

Browser compatibility

:first-child

Internet Explorer
7
Firefox
3.0
Chrome
4.0
Safari
4
Opera
9.5
Mobile
Safari Mobile
3.1
Android
1.0
IE Phone
works
Opera Mobile
10.0