Are you looking for a quick solution to select one or more elements based on their position within a parent element using CSS pseudo-class? Fret not! In this collection, we are showcasing 22+ HTML and CSS nth-child() code examples that allow frontend developers and UI developers to target specific child elements in a web page.

We’ve sourced these examples from Codepen, GitHub, and various other sources, making it easier for professional web developers to apply styles dynamically without requiring extra classes or IDs.

Whether you’re creating a personal website, web applications, e-commerce sites, or blog sites, CSS nth-child offers a modern way to style elements without putting extra lines of codes. We have a wide range of CSS nth-class code snippets allowing frontend developers or web designers to write cleaner markup, enhancing code readability, giving coders better design control, and offering flexibility in web layouts.

Let’s explore our top free CSS nth-child code examples, creating dynamic, responsive user interfaces, and feel the true power of: nth-child() selector

1. CSS :nth-child()


Author:  MUKi
Source:  Code / Demo
Created on: AUGUST 27, 2013
Compatible browsers: Chrome, Firefox, Opera, Edge, Brave
Made with: HTML, CSS(SCSS)

2. CSS – nth-child Selektor


Author: Andreas Lang
Source:  Code / Demo
Created on: DECEMBER 2, 2014
Compatible browsers: Chrome, Firefox, Opera, Edge, Brave
Made with: HTML, CSS

3.  Codepen Challenge : nth-child and Friends


Author: Shruti
Source:  Code / Demo
Created on: DECEMBER 6, 2019
Compatible browsers: Chrome, Firefox, Opera, Edge, Brave
Made with: HTML, CSS

4. December 2019 [week 1]


Author: Nerdy Girl
Source:  Code / Demo
Created on: DECEMBER 8, 2019
Compatible browsers: Chrome, Firefox, Opera, Edge, Brave
Made with: HTML, CSS(SCSS)

5. Equal Height and Width Columns using Flexbox


Author: Karen Menezes
Source:  Code / Demo
Created on: OCTOBER 15, 2013
Compatible browsers: Chrome, Firefox, Opera, Edge, Brave
Made with: HTML, CSS(SCSS)

6. All my children


Author: caroline
Source:  Code / Demo
Created on: DECEMBER 3, 2019
Compatible browsers: Chrome, Firefox, Opera, Edge, Brave
Made with: HTML, CSS

7. CSS Tool: Relearn :nth-of-type(<an-plus-b>) v1.04


Author: Rock Starwind
Source:  Code / Demo
Created on: JUNE 14, 2019
Compatible browsers: Chrome, Firefox, Opera, Edge, Brave
Made with: HTML(Pug), CSS

8. CSS pattern using :nth selector (animated)


Author: Abi Rana
Source:  Code / Demo
Created on: DECEMBER 3, 2019
Compatible browsers: Chrome, Firefox, Opera, Edge, Brave
Made with: HTML, CSS(SCSS), JavaScript

9. Playing with CSS nth-child


Author: Shell Bryson
Source:  Code / Demo
Created on: NOVEMBER 25, 2016
Compatible browsers: Chrome, Firefox, Opera, Edge, Brave
Made with: HTML, CSS(SCSS)

10.  :nth-child / :nth-last-child


Author:  Naoya
Source:  Code / Demo
Created on: JANUARY 18, 2016
Compatible browsers: Chrome, Firefox, Opera, Edge, Brave
Made with: HTML, CSS

11. Henry the nth-child(8)


Author: Katy Cassidy
Source:  Code / Demo
Created on: DECEMBER 5, 2019
Compatible browsers: Chrome, Firefox, Opera, Edge, Brave
Made with: HTML, CSS(SCSS)

12. 12 nth Selectors


Author: Gabriele Corti
Source:  Code / Demo
Created on: DECEMBER 7, 2019
Compatible browsers: Chrome, Firefox, Opera, Edge, Brave
Made with: HTML, CSS(SCSS)

13. CSS :nth-child() pseudo-class


Author: Ricardo Zea
Source:  Code / Demo
Created on: JANUARY 27, 2016
Compatible browsers: Chrome, Firefox, Opera, Edge, Brave
Made with: HTML, CSS(SCSS), JavaScript

14. Triangle Grid with nth-child


Author: Stephen Lee
Source:  Code / Demo
Created on: DECEMBER 4, 2019
Compatible browsers: Chrome, Firefox, Opera, Edge, Brave
Made with: HTML(Haml), CSS(SCSS)

15. CSS :nth-child – Example 1


Author: Daniel Alvarenga
Source:  Code / Demo
Created on: JUNE 23, 2016
Compatible browsers: Chrome, Firefox, Opera, Edge, Brave
Made with: HTML, CSS

16.  0123456789 Rhymes


Author: Ryan Mulligan
Source:  Code / Demo
Created on: DECEMBER 5, 2019
Compatible browsers: Chrome, Firefox, Opera, Edge, Brave
Made with: HTML, CSS(SCSS)

17. Demo: nth-child explained – Keyword


Author: Matt Harris
Source:  Code / Demo
Created on: APRIL 20, 2014
Compatible browsers: Chrome, Firefox, Opera, Edge, Brave
Made with: HTML, CSS(SCSS)

18. Alphabet


Author: Ludmila Tretyakova
Source:  Code / Demo
Created on: DECEMBER 4, 2019
Compatible browsers: Chrome, Firefox, Opera, Edge, Brave
Made with: HTML, CSS(SCSS)

19. :nth-child Flower


Author: Tyler Durrett
Source:  Code / Demo
Created on: DECEMBER 3, 2019
Compatible browsers: Chrome, Firefox, Opera, Edge, Brave
Made with: HTML(Pug), CSS(SCSS)

20. Creating new Selectors with :has(): A :nth-child(n of S) polyfill


Author: Bramus
Source:  Code / Demo
Created on: DECEMBER 13, 2022
Compatible browsers: Chrome, Firefox, Opera, Edge, Brave
Made with: HTML, CSS, JavaScript

21. CodePen Challenge 12/2/2019


Author: Noah
Source:  Code / Demo
Created on: DECEMBER 3, 2019
Compatible browsers: Chrome, Firefox, Opera, Edge, Brave
Made with: HTML, CSS(SCSS)

22. cpc-nth-child


Author: Alyssa
Source:  Code / Demo
Created on: DECEMBER 4, 2019
Compatible browsers: Chrome, Firefox, Opera, Edge, Brave
Made with: HTML, CSS(SCSS)

23. 何番目系の便利なCSSデモ ver2.0


Author: ituki_b
Source:  Code / Demo
Created on: DECEMBER 11, 2018
Compatible browsers: Chrome, Firefox, Opera, Edge, Brave
Made with: HTML, CSS(SCSS), JavaScript