When a CSS rule is not applying, the cause is usually visible in the cascade: another declaration wins, the property is inherited differently than expected, the selector does not match, or the browser is reading a different stylesheet than you think. This guide provides a repeatable browser DevTools workflow for finding the conflict, comparing CSS specificity, checking source order and cascade layers, and fixing the underlying cause without accumulating unnecessary !important declarations.
Overview
CSS does not apply declarations simply because they appear in a stylesheet. For each element and property, the browser evaluates matching rules and determines which declaration wins. That decision is affected by several factors, including whether the rule matches, the origin and importance of the declaration, cascade layers, selector specificity, source order, and inheritance.
A useful debugging habit is to separate the question “Why is my CSS rule not applying?” into smaller questions:
- Does the selector match the element I am inspecting?
- Is the declaration visible in the matched rules list?
- Has the property been crossed out by a stronger declaration?
- Is the value coming from inheritance rather than a direct rule?
- Could a cascade layer, inline style, state selector, or media query be changing the result?
- Is the property itself valid and applicable to this element?
Use the browser’s Elements or Inspector panel rather than guessing from the stylesheet. Select the affected element, open the Styles pane, and inspect the declarations that match it. Crossed-out declarations are useful evidence: they show that the rule was considered but lost to another declaration. The Computed pane then shows the final value and often identifies the rule that supplied it.
What to track
1. Selector matching
First confirm that the selector reaches the intended element. A typo in a class name, an unexpected nesting level, or a state selector such as :hover can make a correct-looking declaration irrelevant. In DevTools, search the Styles pane for the property or selector. If the rule does not appear, check the rendered DOM, class names, conditional markup, and whether the relevant stylesheet loaded successfully.
2. Specificity
Specificity is a comparison system used when competing declarations are otherwise eligible. A practical way to record it is as a three-part value: IDs, classes and attributes, then elements and pseudo-elements.
| Selector | Specificity | Why it matters |
|---|---|---|
p | 0-0-1 | One element selector |
.card | 0-1-0 | One class selector |
article .card | 0-1-1 | One class plus one element |
#checkout .card | 1-1-0 | An ID usually outweighs class-only selectors |
button.primary:hover | 0-2-1 | Two pseudo-class or class-level components plus an element |
style="color: red" | Inline declaration | Often defeats normal stylesheet declarations |
Compare the columns from left to right rather than adding all numbers together. For example, #app .button defeats a selector with many classes because its ID column is higher. Pseudo-classes such as :hover count at the class level, while pseudo-elements such as ::before count at the element level. Selectors such as :where() contribute zero specificity, while the argument of :is(), :not(), or :has() contributes according to the selector used inside it.
3. Source order and cascade layers
If two declarations have the same relevant strength, the later declaration generally wins. Check whether a component stylesheet is loaded before or after a theme stylesheet, and whether a generated stylesheet is being appended later than expected.
Cascade layers add another ordering step. Declarations in a layer are compared according to the layer order before selector specificity is used within the relevant layer. This means a lower-specificity selector in an intentionally later layer can be easier to override than a high-specificity selector in an earlier layer. Inspect the layer information in DevTools when available, and document the intended order in a central place:
@layer reset, base, components, utilities, overrides;Do not assume that increasing specificity is the best response to a layer conflict. Often the cleaner fix is placing a rule in the appropriate layer or changing the layer order deliberately.
4. Inheritance and computed values
Some properties, such as text color and font-related properties, commonly inherit from a parent. Others, such as most margin, padding, border, and layout properties, generally do not. If no direct declaration controls the element, inspect its parent elements and the Computed pane. A child may also be receiving a value through a custom property:
:root { --accent: #2457d6; }
.button { color: var(--accent); }Trace the custom property back to its definition. An undefined variable, fallback value, or overridden variable can make the final declaration look correct while producing an unexpected result.
Cadence and checkpoints
CSS debugging is most effective when it is part of a small recurring review rather than a last-minute search through every stylesheet. Use the following checkpoints during component work and maintenance.
- At the start of a component: record the intended ownership of layout, typography, color, spacing, and interactive states. Decide whether the component uses plain classes, a framework scope, CSS Modules, a utility system, or a design-system layer.
- After a styling change: inspect the affected element in DevTools and check that the expected declaration wins. Capture a regression screenshot or add a focused visual test when the component is important.
- Before merging a refactor: search for new
!importantdeclarations, duplicated selectors, deep nesting, and rules that target generated or unstable class names. - Monthly or quarterly: review the most frequently overridden components, unused selectors, cascade-layer documentation, and browser support assumptions. This is especially useful after reorganizing Sass partials, changing build tooling, or adopting a new framework styling convention.
A simple debugging worksheet can make recurring investigations faster:
- Element: Which exact DOM node has the problem?
- Property: Which property and expected value are affected?
- Matching rules: Which selectors appear in DevTools?
- Winning declaration: Which rule supplies the computed value?
- Rejected declaration: Which expected rule is crossed out, missing, or invalid?
- Reason: Selector mismatch, specificity, layer order, source order, inheritance, state, media query, or invalid value?
- Fix: What is the smallest maintainable change?
How to interpret changes
A change in appearance does not always indicate a specificity problem. Classify the symptom before editing the selector.
If a rule is absent from DevTools, investigate selector matching, stylesheet loading, conditional rendering, or a build error. If it is present but crossed out, compare the winning rule’s layer, specificity, importance, and source position. If it is not crossed out but the visual result is still wrong, verify the property’s value, unit, layout context, and whether another property controls the visible behavior. For example, changing color will not change an SVG icon that uses a separate fill declaration.
Responsive conditions deserve their own check. Expand media queries in DevTools and test the viewport at the width where the problem occurs. A rule may be correct at one width but overridden by a later breakpoint. Also check state and interaction selectors: a focus style, disabled attribute, hover rule, or validation state may intentionally take precedence.
In Sass, inspect the compiled CSS rather than only the nested source. Nesting can quietly produce selectors that are more specific than intended. A rule such as:
.panel {
.title { color: navy; }
}compiles to a descendant selector. In a framework, also inspect whether styles are scoped, injected at runtime, or generated from utility classes. Component scoping can change the selector that reaches the DOM, while utility classes may be intentionally placed in a layer designed to win over component defaults.
Prefer fixes that clarify ownership: reduce unnecessary nesting, use a stable component class, adjust layer placement, or move a shared value into a design token. Reserve !important for deliberate boundaries, such as a utility that must override ordinary component declarations or a narrow accessibility-related rule. Adding it to every failing declaration makes future debugging harder and can force later developers to add even stronger exceptions.
When to revisit
Revisit this guide whenever a component unexpectedly changes appearance, a design-system update affects several screens, or a refactor introduces styling regressions. It is also worth reviewing after a major change to Sass compilation, CSS Modules, utility classes, framework scoping, build order, or cascade-layer organization. Browser DevTools labels and panels can change over time, so refresh screenshots and internal team notes when your primary browser changes its inspection workflow.
For a practical next step, choose one current CSS bug and complete the worksheet from this article without editing the code first. Inspect the exact element, identify the winning declaration, and write down why the intended rule lost. Then apply the smallest fix that improves the cascade rather than merely overpowering it. On your next monthly or quarterly maintenance pass, look for repeated overrides and convert them into clearer component boundaries, documented layers, or shared tokens. This turns CSS cascade debugging from trial and error into a repeatable developer tool workflow.