first-child property CSS Reference

Definition and Usage

The :first-child CSS pseudo-class represents any element that is the first child element of its parent.


element:first-child { style properties }


span:first-child {
    background-color: lime;
  <span>This span is limed!</span>
  <span>This span is not. :(</span>

... should look like ...
This span is limed! This span is not. :(

Example 2 - Using UL

HTML Content

  <li>List 1</li>
  <li>List 2</li>
  <li>List 3</li>

CSS Content

ul li{
ul li:first-child{


Desktop browsers

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 4.0 3.0 (1.9) 7 9.5 4

Mobile browsers

Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 1.0 1.0 (1.9.1) 7 10.0 3.1

Relative articles