A free interactive tool that visualizes CSS :nth-child() and :nth-of-type() selector formulas in real time — type any formula and instantly see which elements match, with plain-English explanations and copy-ready CSS.

CSS :nth-child() Tester is a free, browser-based tool that lets you type any CSS structural pseudo-class formula — odd, even, 3n+1, -n+4 — and instantly see a visual grid highlighting exactly which elements match. It also explains every formula in plain English and gives you a copy-ready CSS snippet.
CSS structural pseudo-classes are powerful but non-obvious. The An+B formula syntax takes practice to read, and making a mistake means refreshing the browser, opening DevTools, inspecting child counts, and guessing again.
Even experienced developers occasionally pause on a formula like :nth-child(-n+3) and need a moment to work it out. Questions like these get Googled thousands of times a day:
Every one of those searches ends in a MDN page, a Stack Overflow answer, or a mental exercise. This tool short-circuits all of that.
Type any valid CSS pseudo-class formula into the input field. The tool accepts the full range of supported syntax:
odd, even3, 7 (matches only that specific child)3n, 3n+1, 2n-1, -n+4, 5n+3The input updates the visual grid with every keystroke — no submit button, no delay.
Switch between :nth-child and :nth-of-type with one click. Both pseudo-classes share the same formula syntax, but their counting behavior differs:
:nth-child counts all sibling elements regardless of tag name:nth-of-type counts only siblings of the same element typeThe visual preview reflects the active selector type in the generated CSS snippet.
A numbered grid (configurable from 4 to 30 elements) shows which positions match the formula. Matching elements are highlighted in the tool's brand color and animated slightly larger. Non-matching elements fade out so the pattern is immediately visible.
A match counter at the top right shows how many elements match out of the total — useful for quickly checking formulas like -n+3 that select a bounded number of elements.
Every formula resolves to a human-readable explanation directly below the input:
odd → "Every odd-numbered element (1st, 3rd, 5th, …) — same as 2n+1."3n+1 → "Every 3rd element, starting from the 1st."-n+4 → "The first 4 elements (counts down from the 4th)."4 → "Matches only the 4th child element."Once the formula looks right, a formatted CSS snippet is ready to copy with one click:
li:nth-child(3n+1) {
/* your styles */
}The snippet uses li as the element selector — change it to match your actual target element before pasting.
The parser handles the full An+B spec:
odd and even keywords — map to 2n+1 and 2n respectivelyAn+B regex pattern to extract A and B components(index - B) is divisible by A with a non-negative quotientEdge cases handled:
A = 0 → matches only position B-n+3 → first 3 elements)n+2 → A = 1)-n → A = -1)Matching grid cells animate with spring physics (stiffness: 400, damping: 25) for a snappy but not jarring response. The layout prop on each cell lets Framer Motion handle position transitions automatically when the element count changes.
tr:nth-child(odd) {
background: #f9f9f9;
}Alternating row colors are the most common use case. The tool shows immediately that odd matches rows 1, 3, 5, and even matches 2, 4, 6.
li:nth-child(-n+3) {
font-weight: bold;
}The negative coefficient pattern is confusing at first. The visual grid makes it click instantly — the formula counts down from 3 to 1, matching exactly the first 3 elements.
.card:nth-child(4n) {
margin-right: 0;
}CSS grid removes the need for this in modern layouts, but it still appears in flexbox grids and older codebases. 4n matches 4, 8, 12 — the last item in each row of a 4-column grid.
.cell:nth-child(3n+1) {
color: brand;
}3n+1 matches positions 1, 4, 7 — the first column of a 3-column layout. Adjust the offset to target any column.
p:first-child /* shorthand for :nth-child(1) */
p:last-child /* no nth-child equivalent */
p:nth-child(1) /* same as first-child */Understanding how 1 as a formula differs from n+1 becomes visual immediately.
DevTools lets you inspect matched elements after the fact, but it doesn't let you experiment with formulas before writing code. The tester is a scratch pad — try formulas freely without touching your stylesheet.
MDN's reference is accurate but static. Reading that -n+3 matches "the first three elements when n is 0, 1, and 2" is less intuitive than seeing boxes 1, 2, and 3 light up immediately.
Setting up a Codepen to test one formula is slow. The tester is open and ready — no account, no editor, no boilerplate.
Try it now: css-nth-child-tester.tools.jagodana.com
The client needed a robust developer tools solution that could scale with their growing user base while maintaining a seamless user experience across all devices.
We built a modern application using CSS and Selectors, focusing on performance, accessibility, and a delightful user experience.
Category
Developer Tools
Technologies
Date
May 2026
More work in Developer Tools