Hosting Solutions
mobile_logo Table of Contents
seal_frontseal_back

nth last child

The nth-last-child structural pseudo-class selector counts inward from the last element of type, to target child elements.
Syntax Logicelement:nth-last-child( integer | divisible_by ) { property_list }

CSS Code Example

Counting upward from the last element to the target element: <style> li:nth-last-child(2) { color: red; } </style> <ul> <li>List item</li> <li>List item</li> <li>List item</li> <li>List item</li> <li>List item</li> </ul> Using divisible_by logic counting upward from the last element: <style> li:nth-last-child(2n+0) { /* Or (even) */ color: red; } </style> <ul> <li>List item</li> <li>List item</li> <li>List item</li> <li>List item</li> <li>List item</li> </ul>

CSS

Selectors

universaltypecompoundclassidnotattributedescendantchildadjacent siblinggeneral siblingfirst childlast childonly childfirst of typelast of typeonly of typenth childnth last childnth of typenth last of typeemptyrootfirst linefirst letterbeforeafterlinkvisitedhoveractivefocustargetenableddisabledcheckedlang