The :Last-of-Type Pseudo-Class

The :last-of-type selector matches every element that is the last child, of a particular type, of its parent. In this demonstration, this selector specifies a background color for the last <p> element of its parent:

HTML file: Displayed by browser:
<style>
p:last-of-type {
    background: #ff0000;
}
</style>
<body>
<h1>This is a heading.</h1>
<p>The first paragraph.</p>
<p>The second paragraph.</p>
<p>The third paragraph.</p>
<p>The fourth paragraph.</p>
</body>

This is a heading

The first paragraph.

The second paragraph.

The third paragraph.

The fourth paragraph.


Note: This is the same as :nth-last-of-type(1).

Back button Table of Contents Next button