CSS :last-of-type Selector

The :last-of-type CSS pseudo-class represents the last element of its type among a group of sibling elements.

The :last-of-type selector allows you to target the last occurence of an element within its container. 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 content.Suppose we have an article with a title, several paragraphs and an image:

:last-of-type is a pseudo-class selector that selects an element that is the last element (sibling) of its type in the list of children of its parent.

In other words, :last-of-type matches the last occurrence of an element inside its parent. For example, the following rule will select and style the last paragraph in .container.

Example -