Interview Question

What are ID selectors?

An ID selector targets the element with a matching unique ID.

💡 Concept ✅ Quick Revision 🎨 CSS

Answer

An ID selector matches an element by its ID value. • It begins with a number sign, such as `#main`. • An ID value should be unique within an HTML document. • ID selectors have high specificity, so classes are often easier to reuse.

💡 Simple Example

#main-content { scroll-margin-top: 5rem; }

⚡ Quick Revision

An ID selector targets the element with a matching unique ID.