pseudo-class

:nth-last-of-type() — CSS reference

Counts same-type element siblings backward. In the example the first paragraph is second from the end among paragraphs.

Formal Syntax & Structure

css syntaxcss
:nth-last-of-type(An+B)

Working Example

Example Snippetcss
<!doctype html><html lang="en"><head><meta charset="utf-8"><title>Selector lab</title><style>:where(.sample) { color: rgb(32, 32, 32); }p:nth-last-of-type(2) { color: rgb(0, 96, 80); }</style></head><body><div><p id="a" class="sample">A</p><span>Spacer</span><p id="b" class="sample">B</p></div></body></html>
CSS Reference