Menu
Coddy logo textTech

Structural pseudo-classes

Part of the CSS Mastery section of Coddy's HTML journey — lesson 12 of 43.

Structural pseudo-classes in CSS are used to style elements based on their position or structure within the HTML document. They allow you to select elements like the first child, last child, or specific numbered children without needing extra classes or IDs.

Common examples include:

  • :first-child — selects the first child of a parent.
  • :last-child — selects the last child of a parent.
  • :nth-child(n) — selects the nth child (e.g., every 2nd, 3rd, etc.).
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

Cheat sheet

Structural pseudo-classes style elements based on their position within the HTML document:

  • :first-child — selects the first child of a parent
  • :last-child — selects the last child of a parent
  • :nth-child(n) — selects the nth child (e.g., every 2nd, 3rd, etc.)

Try it yourself

This lesson doesn't include a code challenge.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in CSS Mastery