← Back to pseudo-classes

CSS Pseudo-class / Element

:last-child

Structural

Selects an element that is the last child of its parent.

Syntax

selector:last-child { }

Example

li:last-child { border-bottom: none; }

Common use cases

  • Removing the last border in a list
  • Styling the last item in a nav differently
  • Avoiding double margins at the end of a container

Practical developer insight

Classic use case: li:last-child { border-bottom: none } to remove the trailing border in a list.

Related