nth-last-child property CSS Reference



Definition and Usage

The :nth-last-child CSS pseudo-class matches an element that has an+b-1 siblings after it in the document tree, for a given positive or zero value for n, and has a parent element. See :nth-child for a more thorough description of the syntax of its argument.


Syntax

element:nth-last-child(an + b) { style properties }

Examples

Example selectors

tr:nth-last-child(-n+4)
Matches the last four rows of an HTML table.
span:nth-last-child(even)
Matches the even elements in their parent element, starting at the last element and working backward.

Compatibility

Desktop browsers

FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support4.03.5 (1.9.1)9.09.53.2

Mobile browsers

FeatureAndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support2.11.0 (1.9.1)9.010.03.2

Relative articles