Interview Question

What is a selector in CSS?

A selector chooses which elements receive a CSS rule.

💡 Concept ✅ Quick Revision 🎨 CSS

Answer

A CSS selector is a pattern that matches elements in a document tree. • Selectors connect a group of declarations to matching elements. • A selector can test element names, classes, IDs, attributes, states, and relationships. • If no element matches, the rule simply applies to nothing.

💡 Simple Example

article > h2 { margin-block-start: 0; }

⚡ Quick Revision

A selector chooses which elements receive a CSS rule.