Skip to content
Justice Tech School

First, Last and nth Child

Structural pseudo classes pick elements by position: :first-child, :last-child, :nth-child(odd), :nth-child(3n) and :only-child.

Example
<style>
li:first-child { color: #5eead4 } li:last-child { color: #f59e0b } li:nth-child(odd) { background: #1e293b }
</style>
<ul><li>One</li><li>Two</li><li>Three</li><li>Four</li></ul>

Exercise

Odd items.

li:nth-child()

Quiz Test

What does :nth-child(3n) select?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.