CSS Specificity: An Overview

  • Specificity is usually the reason why CSS-rules don’t apply to some elements.
  • Every selector has its place in the specificity hierarchy.
  • If two selectors apply to the same element, the one with higher specificity wins.
  • There are four distinct categories which define the specificity level of a given selector: inline styles, IDs, classes+attributes and elements.
  • When selectors have an equal specificity value, the latest rule is the one that counts.
  • When selectors have an unequal specificity value, the more specific rule is the one that counts.
  • Rules with more specific selectors have a greater specificity.
  • The last rule defined overrides any previous, conflicting rules.
  • The embedded style sheet has a greater specificity than other rules.
  • ID selectors have a higher specificity than attribute selectors.
  • You should always try to use IDs to increase the specificity.
  • A class selector beats any number of element selectors.
  • The universal selector and inherited selectors have a specificity of 0, 0, 0, 0.
It is shown in the figure as
CSS Specificity-An Overview
Share this post
[social_warfare]
Cascade Basics
What is Specificity?

Get industry recognized certification – Contact us

keyboard_arrow_up