Interview Question

Difference between class and ID?

Classes are reusable; IDs are unique and have higher selector specificity.

💡 Concept ✅ Quick Revision 🎨 CSS

Answer

Class and ID selectors identify elements differently. • A class is reusable and can match many elements. • An ID should identify one element in a document. • An ID selector has greater specificity than a class selector.

💡 Simple Example

.notice { color: navy; } #urgent-notice { color: crimson; }

⚡ Quick Revision

Classes are reusable; IDs are unique and have higher selector specificity.