- Home
- /
- CSS Specificity
CSS Tutorial
Introduction
CSS Properties
CSS Designing
CSS Advance Topics
CSS FAQs
- Home
- /
- CSS Specificity
CSS Specificity
When multiple CSS rules apply to the same HTM element, CSS Specificity helps the browser decide which one to use. It’s like a rulebook for determining which style wins in case of a conflict.
What Is Specificity?
Specificity is the weight or importance assigned to a CSS rule. The more specific the rule, the more likely it is to apply.
Example to Understand Specificity
Specificity - Learn With Arshyan
Welcome to Learn With Arshyan

Despite all the other rules, the text appears purple because the style attribute has the highest specificity.
Cascade Algorithm
CSS is “Cascading” because it follows this priority chain when applying styles:
- Position (the last style wins if specificity is equal)
- Specificity
- Origin (user agent or author styles)
- Importance (
!important
overrides everything)
Specificity Hierarchy
Selector Type | Specificity Points |
Inline Styles | 1000 |
ID Selectors | 100 |
Class / Attribute / Pseudo-class | 10 |
Element Selectors | 1 |
Universal Selector (*) | 0 |
Specificity Examples
Inline Style
Inline Style Wins

Even if the class or ID tries to change this, orange will appear because inline styles = 1000.
ID Selector
This is styled by ID

Specificity = 100
Class Selector
Class-based styling

Specificity = 10
Element Selector
Styled using an element selector

Specificity = 1
Universal Selector
This is styled by the universal selector

Specificity = 0
Specificity Calculation Example
a.arshyan-class.study-group[href]:hover {
color: purple;
}
Breakdown:
a
= 1 (element).arshyan-class
and.study-group
= 10 + 10[href]
= 10:hover
= 10
Total Specificity = 1 + 10 + 10 + 10 + 10 = 41
!important
If you really want a style to override everything else:
p {
color: black !important;
}
Even inline styles won’t beat this. But use !important
sparingly, as it makes debugging difficult.