What is the priority of the ID selector?
The ID selector has very high priority, it ranks above class and tag selectors, but below inline styles and !important.
If expressed through the specificity formula [a, b, c, d], ID gives 1 point in digit b, that is:
javascript
#header → [0, 1, 0, 0]
.class → [0, 0, 1, 0]
div → [0, 0, 0, 1]Summary of selector priority (top to bottom)
!important- inline styles (
style="") - ID selectors (
#id) - class, attribute, pseudo-class selectors
- tag selectors
- default browser styles
Thus, the ID selector has one of the highest priorities among regular CSS selectors and almost always "wins" over a class or tag if they conflict.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.