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

The :nth-last-of-type selector allows you select one or more elements based on their source order, according to a formula. It is defined in the CSS Selectors Level 3 spec as a “structural pseudo-class”, meaning it is used to style content based on its relationship with parent and sibling elements. It functions the same as :nth-of-type except it selects items starting at the bottom of the source order, not the top.

Suppose we have an unordered list and wish to highlight the second-to-last item (in this exact example, the "Fourth Item")

Specify a background color for every <p> element that is the second p element of its parent, counting from the last child

Using a 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:

Example -