Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

CSS3 :last-child selector

CSS3 :last-child selector

Complete CSS SelectorComplete CSS Selector Reference Manual

Example

Specify the background color of the last p element in the parent:

p

:last-child

{

background:

#ff0000

;

}

Try it »


Definition and Usage

:last-child selector is used to match the last child element of a parent.

Tip: p:last-child is equivalent to p:nth-last-child(1).


Browser support

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

Selector
:last-child 4.0 9.0 3.5 3.2 9.6

More examples

Example

Specify the last li element in the parent ul and set its background color:

li

:last-child

{

background-color:

#ff0000

;

}

Try it »


Complete CSS SelectorComplete CSS Selector Reference Manual