Unsere Freiwilligen haben diesen Artikel noch nicht in Deutsch übersetzt. Machen Sie mit und helfen Sie, das zu erledigen!
Sie können den Artikel auch auf English (US) lesen.


The :nth-last-child(an+b) 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. In level 3 implementations, the matching element is required to have a parent. In level 4 implementations it does not.

In effect, it functions the same as :nth-child except it selects items counting backwards from the end of element series, not the start.

See :nth-child for a more thorough description of the syntax of its argument.


:nth-last-child( <an-plus-b> [ of <selector># ]? ) { style properties }

<an-plus-b> = An+B | even | odd


Example selectors

Matches the last four rows of an HTML table.
Matches the even elements in their parent element, starting at the last element and working backward.


This CSS ...

table {
  border: 1px solid blue;
tr:nth-last-child(-n+3) { /* the last 3 siblings */
  background-color: lime;

... with this HTML ...

      <td>First line</td>
       <td>Second line</td>
       <td>Third line</td>
       <td>Fourth line</td>
       <td>Fifth line</td>

... looks like :


Specification Status Comment
Selectors Level 4
The definition of ':nth-last-child' in that specification.
Working Draft Matching elements are not required to have a parent.
Selectors Level 3
The definition of ':nth-last-child' in that specification.
Recommendation Initial definition.

Browser compatibility

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support 4 (Yes) 3.5 (1.9.1) 9.0 9.5 3.2
No parent required 57 ? ? ? 44 ?
Feature Android Webview Chrome for Android Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) 1.0 (1.9.1) 9.0 10 3.2
No parent required 57 57 ? ? ? 44 ?

See also

Schlagwörter des Dokuments und Mitwirkende

 Zuletzt aktualisiert von: jpmedley,