<ol>
    <li>li</li>
    <li>li</li>
    <li>li</li>
    <li>li</li>
</ol>
li:last-child {
    background-color: yellowgreen;
}
Rendered Output
:last-child {
    /* ... */
}
<article>
    <h2>Heading Element</h2>
    <p>Paragraph 1</p>
    <p>Paragraph 2</p>
</article>
article p:last-child {
    background-color: yellowgreen;
}
Rendered Output
<article>
    <div>This 'div' is the first one.</div>
    <div>This <span>nested 'span' is both the first and the last one.</span>!</div>
    <div>
        This <em>nested 'em' is the first one.</em>, but this <em>nested 'em' is the last one.</em>!
    </div>
    <div>This <span>nested 'span' is styled. It is both the first and the last one.</span>!</div>
    <p>This 'p' is not the last child.</p>
    <div>This 'div' is the last one.</div>
</article>
article *:last-child {
    background-color: yellowgreen;
}
Rendered Output

Last updated: 2025-09-25

See more details on caniuse.com.