:last-of-type CSS Pseudo Class

Description

The :last-of-type pseudo-class is a selector in CSS (Cascading Style Sheets) that allows you to target the last element of a specific type within its parent element. It is used to apply styles to the final element of a particular type within a container, such as the last paragraph in a div or the last list item in an unordered or ordered list.

Here's a simple example of how you might use the :last-of-type pseudo-class in CSS:

p:last-of-type {
font-weight: bold;
color: blue;
}

In this example, all the last paragraphs (<p>) within their respective parent containers will have their text made bold and colored blue.

This pseudo-class is helpful for applying distinct styling to the last occurrence of an element type without needing to add specific classes or IDs to those elements.

Syntax

:last-of-type {
  /* ... */
}

Example

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,</p>
<p>quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident,</p>
<p>sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
p:last-of-type { 
font-style: italic;
color: #3e79f9;
}

Browser Support

The following table will show you the current browser support for the CSS :last-of-type pseudo class.

Desktop
Edge Chrome Firefox Opera Safari
1213.59.53.1
Tablets / Mobile
Chrome Firefox Opera Safari Samsung Webview
18410.1212

Last updated by CSSPortal on: 1st October 2023