Skip to main content
InterviewHubPRO
Section Overview
Q3

Question 3 of 50

Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

6%
CSS3 & Modern Layouts (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

How is CSS Specificity calculated? (The 3-Value Tuple Formula).

junior LevelCode ExampleForms

In Simple Words: When multiple conflicting CSS rules target the same element, the browser calculates Specificity to decide which rule wins. Modern CSS calculates specificity as a 3-component tuple (A, B, C):

less
( A , B , C )
  |   |   |
  |   |   +--> C: Type selectors (div, p, h1) and Pseudo-elements (::before, ::after)
  |   +------> B: Class (.card), Attribute ([type="text"]), and Pseudo-classes (:hover, :has())
  +----------> A: ID selectors (#header, #user-profile)
  • Inline styles (style="...") override all (A, B, C) declarations.
  • !important overrides everything, creating an independent cascade priority tier.
  • Comparison: Compare tuples from left to right:
    • (1, 0, 0) (#nav) beats (0, 15, 20) (15 classes and 20 tags).
    • (0, 2, 1) (.menu .active a) beats (0, 1, 5) (.menu div ul li a).
    • If specificity is equal, the rule defined later in the stylesheet wins (Source Order).