:nth-last-child()

Works exactly like :nth-child(), but it counts backwards from the very last element in the container.

/* Usage Example */
li:nth-last-child(2) {
  /* Targets the second-to-last item in a list */
  color: #ef4444;
}
Widely available Since 2015 96% global usage

This feature is well established and works across many devices and browser versions. It has been available across browsers since 2015.

4+
3.5+
3.1+
12+
Kinsta

Your first month is free

Managed WordPress hosting for faster sites.

Learn more

New CSS drops.

Join 600+ readers who've survived clearfix hacks.

ESC