gpt-4.1-mini-2025-04-14· OpenAI
WildChat-4.8M (AI2)
can i put multiple numbers in nth-child() css?
- User
can i put multiple numbers in nth-child() css?
- Assistant
No, you cannot directly put multiple numbers inside a single
nth-child()selector in CSS, likenth-child(2, 4, 6)— this is not valid syntax.However, if you want to select multiple specific children, you have a few options:
1. Use multiple selectors separated by commas
li:nth-child(2), li:nth-child(4), li:nth-child(6) { /* styles here */ }2. Use
:nth-child()with formulas if the numbers follow a patternFor example, to select every even child:
li:nth-child(even) { /* styles here */ }Or every 3rd starting from 2:
li:nth-child(3n + 2) { /* styles here */ }3. Use the
:is()pseudo-class (CSS Selectors Level 4)This allows grouping of multiple selectors more cleanly:
li:is(:nth-child(2), :nth-child(4), :nth-child(6)) { /* styles here */ }Note that browser support for
:is()is generally good in modern browsers.
You cannot put multiple values inside a single , but you can group multiple selectors via comma, or use with multiple arguments to apply styles to multiple children.