:last-of-type
Quick Summary for :last-of-type
The :last-of-type CSS pseudo-class represents the last element of its type among a group of sibling elements.
Code Usage for :last-of-type
/* Selects any <p> that is the last element    of its type among its siblings */ p:last-of-type {   color: lime; } 
More Details for :last-of-type

:last-of-type

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

/* Selects any <p> that is the last element    of its type among its siblings */ p:last-of-type {   color: lime; } 

Note: As originally defined, the selected element had to have a parent. Beginning with Selectors Level 4, this is no longer required.

Syntax

:last-of-type

Examples

Styling the last paragraph

HTML
<h2>Heading</h2> <p>Paragraph 1</p> <p>Paragraph 2</p> 
CSS
p:last-of-type {   color: red;   font-style: italic; } 
Result

Nested elements

This example shows how nested elements can also be targeted. Note that the universal selector (*) is implied when no simple selector is written.

HTML
<article>   <div>This `div` is first.</div>   <div>This <span>nested `span` is last</span>!</div>   <div>This <em>nested `em` is first</em>, but this <em>nested `em` is last</em>!</div>   <b>This `b` qualifies!</b>   <div>This is the final `div`!</div> </article> 
CSS
article :last-of-type {   background-color: pink; } 
Result

Specifications

Specification
Selectors Level 4 # last-of-type-pseudo

See also

:last-child, :nth-last-of-type Select your preferred language English (US)DeutschEspañolFrançais日本語Português (do Brasil)Русский中文 (简体) Change language

No Items Found.

Add Comment
Type in a Nick Name here
 
Other Categories in CSS
css
Search CSS
Search CSS by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

You could also follow me on twitter. I have a couple of youtube channels if you want to see some video related content. RuneScape 3, Minecraft and also a coding channel here Web Dev.

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote
In this case my anchor this week becomes driving almost 2hrs outside of Atlanta to one of my favorite hard core gyms in the world.. MetroFlex aka The Dungeon. The gym owners turn the heat way up so it becomes a fun sweat box and the gym members just watch from afar and leave me alone. I happily drive myself long distances to find MY ANCHOR. Our anchor allows us to have balance, focus and be as productive as possible. And if you're in the middle of a heavy set and your headphones start to fall off your head, like mine did here.. well.. f*ck the headphones. Let em break and fall. You can always get a new pair, but the iron ain't ever gonna lift itself.
Unknown
Random CSS Property

:nth-last-of-type()

The :nth-last-of-type() CSS pseudo-class matches elements based on their position among siblings of the same type (tag name), counting from the end.
:nth-last-of-type css reference