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 to fully support the pseudo-class.

Chrome Edge Firefox Safari Opera
4.0 9.0 3.5 3.2 9.6

Related Pages

Reference:CSS :last-of-type pseudo-class