nth-last-of-type property CSS Reference



Definition and Usage

The :nth-last-of-type CSS pseudo-class matches an element that has an+b-1 siblings with the same element name 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-of-type(an + b) { style properties }

Examples

<div>
  <span>This span is first!</span>
  <span>This span is not. :(</span>
  <em>This one is odd. </em>
  <span>But this one is!</span>
  <strike>This is another type</strike>
  <span>Sadly, this one is not...</span>
</div>
span:nth-last-of-type(2) {
  background-color: lime;
}

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

Syntax

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

Last Type Example

<div>
      <span>This span is first!</span>
      <span>This span is not. :(</span>
      <em>This one is odd. </em>
      <span>But this one is!</span>
      <strike>This is another type</strike>
      <span>Sadly, this one is not...</span>
    </div>
span:nth-last-of-type(2) {
      background-color: lime;
    }

Relative articles