Interview Question

What is specificity in CSS?

Specificity is one stage of the cascade, not the complete winner-selection rule.

💡 Concept ✅ Quick Revision 🎨 CSS

Answer

Specificity compares selector weights when competing declarations have the same origin, importance, and layer order. • ID selectors contribute more specificity than class, attribute, and pseudo-class selectors. • Type selectors and pseudo-elements contribute a lower component. • Specificity does not override declarations from a higher-priority cascade origin or layer.

💡 Simple Example

.message { color: navy; } #warning { color: crimson; }

⚡ Quick Revision

Specificity is one stage of the cascade, not the complete winner-selection rule.