Latest web development tutorials

CSS: first-child pseudo-element

CSS selectors complete CSS selectors complete reference manual

Examples

Match elements belonging to the first child of the parent element of each <p> element

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

try it"

Definition and Usage

: Only-child selector matches the element belonging to the parent element only child element.


Browser Support

Figures in the table represent the first browser to support the version number of the property.

选择器
:first-child 4.0 7.0 3.0 3.1 9.6

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


related articles

CSS tutorial: CSS pseudo-classes


Examples

More examples


Examples

<P> element is the first child of its parent, style <i> element for each <p> element is:

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

try it"

Examples

List first <li> element selected style:

li:first-child
{
background:yellow;
}

try it"

Examples

Each <ul> element's first child element selected style ::

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

try it"


CSS selectors complete CSS selectors complete reference manual