Full answer
When a rule seems ignored, do not edit blindly. Follow the same steps each time.
- Inspect the element in DevTools. Check that the element is the one you think it is, and that the rule appears in the Styles pane. If the rule is not listed, the selector did not match or the file did not load. Check the Network panel and the selector spelling.
- Look at how the rule is shown. A line with a strike-through lost to another rule, which is shown above it. A warning icon beside a declaration means the property name or value is invalid, and the browser dropped it.
- Check the Computed pane for the final value, and expand it to see which rule won.
- Think about the cascade in order: origin and
!important, then layers, then specificity, then source order. - Look for typos, missing semicolons, wrong units and a missing closing brace.
- Check inherited and parent effects: the property may not apply to that element type, or a parent may hide or clip it.
Here is a small page with four bugs. Each one has a different cause.
What happens and why:
- The title stays black, because
colouris not a property. The browser ignores the declaration. - The note keeps the default size, because
1,2remis not a valid length. The decimal separator must be a dot. - The link is gray, not blue. The selector
#side ahas an id and wins on specificity over.link, even though.linkis later. - The tag has no colour and no background. A missing semicolon makes
crimson background: yellowone invalid value, and the whole declaration is dropped, including the colour.
The fixed version:
<style>
.title { color: crimson; }
.note { font-size: 1.2rem; }
#side a.link { color: blue; }
.tag { color: crimson; background: yellow; }
</style>
<h2 class="title" id="title">Title</h2>
<p class="note" id="note">Note text</p>
<div id="side"><a class="link" id="link" href="#x">Link</a></div>
<span class="tag" id="tag">Tag</span>For the link, the better long-term fix is to lower the specificity of #side a to a class, and not to raise .link with more ids. Avoid !important unless you have no other way.
After the fix, reload without cache and recheck the Computed pane.
<style>
.title { colour: crimson; }
.note { font-size: 1,2rem; }
#side a { color: gray; }
.link { color: blue; }
.tag { color: crimson background: yellow; }
</style>
<h2 class="title" id="title">Title</h2>
<p class="note" id="note">Note text</p>
<div id="side"><a class="link" id="link" href="#x">Link</a></div>
<span class="tag" id="tag">Tag</span>The page was run twice, once with the bugs and once fixed, and the computed values were read from both. Run in Chrome 156 (headless) as a page; the snippet is wrapped in a minimal HTML document with doctype, charset and viewport meta tag. Two full runs gave identical results, and the measured values in the answer come from them.
Key points
- Find out whether the selector matches and the file loads.
- A strike-through means the rule lost; a warning icon means it was invalid.
- The cascade order is importance, layers, specificity, source order.
- Typos, bad units and missing semicolons are common causes.
- Avoid !important as a first fix.
Common mistakes
- Adding !important to every rule that seems ignored, which makes the cascade harder to manage.
- Not looking for the invalid-declaration warning in the Styles pane.
- Changing the selector many times without checking whether it matches the element.
Follow-ups
- How do you tell an invalid declaration from one that lost the cascade?
- Why is !important a poor first fix?
Tips
- Give a repeatable order of checks, not a guess.
- Name DevTools features: strike-through, warning icon and the Computed pane.