What is specificity in CSS?

Specificity is the way the browser decides which rule wins when more than one rule applies to the same element. A stronger selector wins.

  • Inline style is the strongest.
  • Then #id selectors.
  • Then .class, [attribute] and :pseudo-class.
  • The weakest are element selectors like p.
p { color: blue; }
.note { color: green; }
#intro { color: red; }   /* wins for <p id="intro" class="note"> */

If the specificity is equal, the later rule wins. See CSS Specificity.


Learn more about the similar topics:
Tutorials
CSS Selectors
CSS Specificity
CSS Pseudo-classes and Pseudo-elements
Exercises & Assignments
No Content Found.
Interview Questions & Answers
What is the CSS class selector?
What is grouping in CSS and what is it used for?
What are child selectors in CSS?
What is the difference between id and class selector in CSS?
What is specificity in CSS?
What does !important do in CSS?
What are pseudo-classes and pseudo-elements in CSS?