CSS :last-child pseudo-class

Definition and usage

CSS :last-child Pseudo-classes are used to match any element that is the last child of its parent element.

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

Example

Specify the background color for the <p> element that is the last child of its parent element. Also specify the background color for the <li> element that is the last child of its parent element:

p:last-child {
  background-color: yellow;

li:last-child {
  background-color: yellow;

Try it yourself

CSS syntax

:last-child {
  css declarations;

Technical details

Version: CSS3

Browser support

The numbers in the table specify the first browser version that fully supports this pseudo-class.

Chrome Edge Firefox Safari Opera
4.0 9.0 3.5 3.2 9.6

Pagine correlate

Riferimento:Pseudo-classe CSS :last-of-type