Interview Question

What is nth-child selector?

`nth-child()` counts an element’s position among its siblings.

💡 Concept ✅ Quick Revision 🎨 CSS

Answer

The `:nth-child()` pseudo-class matches elements by their position among siblings. • Its counting includes every element sibling unless an `of` selector filters the list. • It accepts keywords, numbers, or An+B formulas. • The match depends on sibling order in the document.

💡 Simple Example

li:nth-child(odd) { background: #f2f2f2; }

⚡ Quick Revision

`nth-child()` counts an element’s position among its siblings.