THE GITHTML FIELD GUIDE
Why a CSS override loses across cascade layers
A later CSS rule can lose when cascade layers place it below another declaration. Inspect layer order, unlayered rules, importance, and specificity rather than assuming the last line always wins. Fix the stylesheet's intended precedence deliberately; adding important declarations indiscriminately makes a portable document harder to understand and maintain.
Identify the specific failure
Cascade layers introduce an ordering step before specificity for declarations of the same origin and importance. Normal unlayered rules can outrank normal layered rules. Important declarations have different ordering behavior, so a familiar specificity explanation may be incomplete.
Make a narrow correction
Use the computed-style view to identify the winning declaration and its layer. Consolidate the reading copy's small style set where practical. If layers remain useful, declare their order clearly and put overrides in the intended layer.
- Locate the winning declaration and its layer before changing the selector.
- Inspect important flags separately from ordinary layer precedence.
- Document the intended layer order rather than relying on accidental concatenation.
@layer base, report;
@layer report { .summary { font-weight: 700; } }Read the winning declaration before increasing specificity
Imagine a report imports a component theme into a base layer and defines an intended correction in a later report layer. The correction should outrank a normal base-layer declaration even if its selector is less specific. If it does not, inspect whether a competing declaration is actually unlayered, marked important, or from another origin. The first useful evidence is the browser's winning declaration and the crossed-out alternatives, not the apparent order of the text in one source file.
Layer order is established when layers are first declared. Reopening an existing layer farther down the stylesheet adds rules without moving that layer to the end of the precedence order. This matters when an export concatenates several stylesheets: the first occurrence may be in a small reset file, while the author is looking at a much later block. Write an explicit layer-order statement near the beginning when the design genuinely needs several layers, then keep each component's declarations in the layer that expresses its intended responsibility.
Treat important declarations as a separate branch of the investigation because their layer ordering is reversed. Adding important to a losing declaration can appear to solve the immediate symptom while creating a new ordering surprise elsewhere. For a small reading artifact, reducing the stylesheet to a clear baseline and a few intentional overrides may be easier to maintain than preserving an application's complete layer hierarchy. Verify one normal override and any deliberately important exception independently, and record why an exception exists rather than allowing it to become the template for every future correction.
Verify the repaired artifact
Test one property with a visible effect, then review related states such as links and callouts. A broad override can fix one paragraph while weakening another component.
Sources and further reading
AI-assisted writing with source-linked guidance and illustrative examples. Read our editorial approach or report a correction.