Specificity
CSS specificity is the priority assigned to a selector that helps determine which matching declaration takes precedence in the cascade when styles conflict.
CSS in Depth, Second Edition
A numeric representation of a selector's counts of IDs, classes, and tags, ordered from highest to lowest priority.
- How it is used
- Resolves conflicting CSS declarations by comparing selectors when earlier cascade criteria leave the conflict unsettled.
- How deep it goes
- Works through numeric selector counts, competing fixes, source-order ties, and specificity control with `:where()` and nesting.
- Examples
- Uses conflicting navigation-link colors, ranked heading selectors, a link styled as a button, and a nested selector list.
- What you can do after
- Diagnose/debug with it when a CSS rule loses, then adjust selectors or reduce specificity to express the intended priority.
Read how CSS in Depth, Second Edition explains specificity →
Acing the Frontend Interview
CSS specificity is the precedence system browsers use to determine which matching style declaration wins when rules conflict.
- How it is used
- Resolves conflicting CSS declarations and supports interview questions about targeting elements.
- How deep it goes
- Works through competing selectors and their resulting styles, without presenting a numeric specificity formula.
- Examples
- Uses a React button matched by element, class, nested-class, and ID selectors.
- What you can do after
- Diagnose/debug with it: identify which matching declaration supplies each button style and explain the result.
Read how Acing the Frontend Interview explains specificity →
React in Depth
CSS specificity is the priority calculation that determines which applicable CSS rule overrides another when their declarations conflict.
- How it is used
- Determines which conflicting CSS declaration overrides another and frames styling decisions in component-based applications.
- How deep it goes
- Defines priority, demonstrates a button override, and stops short of detailing the underlying selector-scoring algorithm.
- Examples
- Uses green and purple button rules, .button and .custom-button, and styled-components rule ordering.
- What you can do after
- Diagnose conflicting rules across CSS files and choose managed ordering when component-scale specificity becomes difficult to maintain.
Tiny CSS Projects
CSS specificity is the precedence score used to determine which competing selector-based declarations apply to an element.
- How it is used
- Resolves competing CSS declarations and supports deliberate overrides in responsive layouts and form controls.
- How deep it goes
- Explains selector scoring, inheritance, stylesheet order, !important, and modern :is() and :where(), without formal browser internals.
- Examples
- Uses inherited body and paragraph colors, table header alignment, inline headings, and styled radio buttons and checkboxes.
- What you can do after
- Diagnose conflicting declarations and apply targeted selector, order, inheritance, or cascade changes.
Web Design Playground, Second Edition
CSS specificity is the ranking assigned to a selector that determines its precedence among competing style rules targeting the same element.
- How it is used
- Resolves conflicts among CSS declarations that target the same element, especially when the declarations share a source.
- How deep it goes
- Explains selector scoring with I-C-T comparisons and worked rules, while leaving the wider cascade as surrounding context.
- Examples
- Uses competing p, class, descendant, and combined selectors to calculate scores and determine a paragraph’s rendered color.
- What you can do after
- Diagnose which competing CSS selector wins by calculating and comparing its specificity.
Read how Web Design Playground, Second Edition explains specificity →
Web Design Playground
The CSS rule-ranking system that compares selectors to decide which declaration wins when multiple rules apply to the same element.
- How it is used
- Resolves competing CSS declarations that target the same element from the same style source.
- How deep it goes
- Works through a point-counting recipe and color-rule comparison, but does not detail how equal scores are resolved.
- Examples
- Compares four color rules targeting one paragraph, with selector scores of 11, 10, 2, and 1.
- What you can do after
- Diagnose/debug with it when a CSS rule appears not to apply because another selector has greater weight.
Web Components in Action
CSS specificity is the precedence system that determines which competing stylesheet declarations apply to an element.
- How it is used
- Uses specificity to prevent and diagnose CSS style creep around Web Components.
- How deep it goes
- Explains selector scoping, conflicting button rules, inherited variables, and `:root` baselines through working examples.
- Examples
- Uses a styled stepper, global button rules, scoped button overrides, and inherited theme variables.
- What you can do after
- Diagnose style creep by narrowing selectors and tracing inherited custom-property values across component boundaries.
Also covered in
- Vanilla WebIn early access (MEAP)
What to know first
- CSSCSS (Cascading Style Sheets) is a stylesheet language for specifying the presentation and layout of structured documents.
- CSS selectorA CSS selector is a pattern that matches elements in a document according to their names, attributes, relationships, states, or other conditions.
- cascadeThe CSS cascade is the process that resolves competing applicable style declarations to determine the styles applied to an element.
- CSS classA name assigned to one or more document elements through a class attribute, allowing CSS selectors to match them and apply shared style declarations.
Related concepts
- cascade layercontrasts with · A CSS cascade layer is a named or anonymous group of declarations whose precedence is explicitly ordered within the cascade.
- :where()addressed by · The CSS :where() pseudo-class matches elements against a selector list while contributing zero specificity.
- cascadeused by · The CSS cascade is the process that resolves competing applicable style declarations to determine the styles applied to an element.
- CSSpart of · CSS (Cascading Style Sheets) is a stylesheet language for specifying the presentation and layout of structured documents.
- CSS selectormeasures · A CSS selector is a pattern that matches elements in a document according to their names, attributes, relationships, states, or other conditions.
- CSS scopecontrasts with · CSS scope is a language feature that limits style rules to elements within a specified region of a document.
Questions about specificity
What is specificity?
CSS specificity is the priority assigned to a selector that helps determine which matching declaration takes precedence in the cascade when styles conflict.
Which Manning books explain specificity?
CSS in Depth, Second Edition, Acing the Frontend Interview, React in Depth, Tiny CSS Projects, Web Design Playground, Second Edition, Web Design Playground and Web Components in Action.
What should I know before learning specificity?
Manning books that teach specificity usually introduce CSS, CSS selector, cascade and CSS class first.
What is the difference between specificity and cascade layer?
CSS specificity is the priority assigned to a selector that helps determine which matching declaration takes precedence in the cascade when styles conflict. A CSS cascade layer is a named or anonymous group of declarations whose precedence is explicitly ordered within the cascade.
What is specificity part of?
Specificity is part of CSS. CSS (Cascading Style Sheets) is a stylesheet language for specifying the presentation and layout of structured documents.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.






