What is CSS nth-of-type?

The CSS nth-of-type(n) selector matches every element of a specific type that is the nthn^{th} child of its parent.

n can be any of the following:

  • number
  • keyword
  • formula.

Syntax

: nth-of-type(number) {
  // css 
}

The code below shows how different stylings can be applied to different paragraphs based on their nth value.

New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
šŸ† Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved