Example 1 — Style the Last List Item
Highlight the last li in a list.
<style>
li:last-child {
border: 2px solid orange;
}
</style>
<ul>
<li>Adhemar da Silva</li>
<li>Wang Junxia</li>
<li>Wilma Rudolph</li>
</ul> How It Works
- Pick the tag.
li:last-childonly considers list items. - Require last place. The
limust also be the parent’s last element child. - Style that item. An orange border marks the match.
- Others stay plain. Earlier items are not last children.

