What is the CSS nth-child Tester?
Test nth-child and nth-of-type selector patterns visually. Enter any An+B formula and see which list items match in real-time.
Everything runs locally in your browser. Adjust the controls above, preview instantly, and copy clean, production-ready CSS — no account, no upload.
Using the CSS nth-child Tester
Everything lives in the panel at the top of this page. There is nothing to install — it all runs right here in your browser.
Enter an An+B formula
Type a formula like 2n+1, 3n, -n+3, or a keyword like odd or even. The tester highlights matching items in the preview list.
Adjust list length
Change the number of items in the preview to test how the formula behaves with different list lengths.
Copy the selector
Click Copy to get the :nth-child(formula) selector.
What the generated code looks like
Clean, production-ready CSS — no vendor bloat, no unnecessary declarations.
/* Every odd item */
li:nth-child(odd) { background: #f5f5f7; }
/* Every 3rd item */
li:nth-child(3n) { color: #0071e3; }
/* First 3 items */
li:nth-child(-n+3) { font-weight: bold; }
/* Items 4 through 8 */
li:nth-child(n+4):nth-child(-n+8) { opacity: 0.5; }
/* Last item */
li:last-child { border-bottom: none; }
/* Every 2nd item starting from 4th */
li:nth-child(2n+4) { background: #e8f0fe; }Common mistakes & how to fix them
A few habits trip people up. Here is what to watch for — and the exact fix.
Confusing nth-child with nth-of-type
:nth-child(2) selects the second child of its parent regardless of element type. If the second child is a <span> not a <p>, a p:nth-child(2) selector matches nothing.
Fix: Use :nth-of-type when you want the second element of a specific type. Use :nth-child when you want the nth DOM node regardless of type.
Pro tips for better results
Range pattern: :nth-child(n+A):nth-child(-n+B)
To select items A through B, chain two nth-child selectors: li:nth-child(n+3):nth-child(-n+7) selects items 3, 4, 5, 6, and 7.
Frequently asked questions
From the blog
Read more →CSS clamp() and Fluid Typography: Stop Writing Font-Size Media Queries (2026)
Learn how CSS clamp() creates type that scales smoothly between screen sizes with a single line, the formula behind it, and how to build a fully fluid type scale without media queries.
CSS Grid vs Flexbox: Which Should You Use? (2026)
CSS Grid vs Flexbox, settled. Here's a senior dev's honest breakdown of when to use each, with real code examples, a comparison table, and no hedging.
CSS Animations: A Practical Guide to Keyframes and Transitions (2026)
Learn the difference between transitions and keyframe animations, how to write @keyframes, the properties worth animating for 60fps, and easing that actually looks good.