Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Pseudo-classes

The :last-of-type pseudo-class

Reference for the CSS :last-of-type pseudo-class: select the last sibling with a given tag name, with syntax, examples, comparison with :last-child and support.

The :last-of-type pseudo-class matches an element that is the last among its siblings with the same tag name. In a parent with several paragraphs followed by a footer, p:last-of-type picks the final paragraph, even though the footer comes after it.

Compare :last-child, which only looks at position and would fail here.

CSS
p:last-of-type {
  margin-bottom: 0;
}

Try it

Last paragraph before a footer

Syntax

CSS
:last-of-type { /* declarations */ }

No arguments; specificity (0,1,0).

Syntax and arguments

Part Description
:last-of-type Matches an element with no following sibling of the same element type.
No arguments The pseudo-class is not functional.
Equivalent :nth-last-of-type(1)
Type The tag name only; classes and attributes do not affect the count.

Usage notes

  • Other tags are ignored. A trailing <footer>, <script> or <div> does not prevent the last p from matching.
  • Classes don't change the count. .note:last-of-type matches an element with that class only if it is also the last of its tag in its parent.
  • Common uses. Trimming the bottom margin of the last paragraph in a card, or styling the last figure, image or list in a section.
  • Mixed content. If you want "the last li", li:last-child and li:last-of-type agree when only li elements are siblings; they differ when other tags are mixed in.
  • Each parent counts separately. Every container has its own last element of each type.

Browser support

Supported in every browser.