Easy Tutorial
❮ Sel All Css3 Browsersupport ❯

CSS3 :nth-last-of-type() Selector

Complete CSS Selectors Reference

Example

Specify the background color for each p element that matches the second-to-last sibling element of its type:


Definition and Usage

The :nth-last-of-type(*n*) selector matches the nth last sibling element of its type.

n can be a number, a keyword, or a formula.

Tip: See the :nth-last-child() selector. This selector matches the nth last structural child element of its parent.


Browser Support

The numbers in the table specify the first browser version that fully supports the property.

Selector
:nth-last-of-type() 4.0 9.0 3.5 3.2 9.6

More Examples

Example 1

Odd and even are keywords that can be used to match child elements whose index is odd or even.

Here, we specify two different background colors for odd and even last p elements:

Example 2

Using the formula (an+b). Description: a represents a cycle size, n is a counter (starts at 0), and b is an offset value.

Here, we specify a background color for all p elements whose index is a multiple of 3 in last order:


Complete CSS Selectors Reference

❮ Sel All Css3 Browsersupport ❯