Sub topic 16
Debugging Conflicting Styles in Developer Tools
This chapter assumes you can read selectors, calculate a specificity triple (IDs, classes/attributes/pseudo-classes, types/pseudo-elements), and know the cascade order of origin, importance, layers, specificity, and source order. Here you apply that knowledge in the browser's developer tools. The steps below use Chrome, Edge, and Firefox terms, which are nearly identical.
A Worked Problem
Suppose a link should be blue, but it renders black.
<nav id="nav">
<a class="link" href="/home">Home</a>
</nav>#nav a { color: black; }
.link { color: blue; }The two rules target the same element. The first has specificity (1,0,1) and the second has (0,1,0). The ID rule wins, so the link is black. Developer tools show you this without any arithmetic.
Reading the Styles Panel
- Right-click the element and choose Inspect.
- Open the Styles pane (called Rules in Firefox).
- Read the rules from top to bottom. The rule that wins is listed first, and rules that lose are listed below it.
- Look for a line through a declaration. A struck-through declaration lost the cascade or was invalid.
In the example, #nav a appears above .link, and color: blue is struck through. The panel orders rules by the cascade, so you can read the answer directly.
What the Markers Mean
| What you see | What it means |
|---|---|
| Struck-through declaration | A higher-priority rule overrode it |
| Warning icon next to a declaration | The property name or value is invalid, or the property has no effect here |
| Grayed-out declaration | It is valid but not applied, for example `z-index` on a non-positioned element |
| File name and line number on the right | The stylesheet and line where the rule is defined |
| Rule under "Inherited from" | The value came from an ancestor, not from a rule on this element |
Using the Computed Pane
The Computed pane shows the final value of each property. Expand a property such as color to see every rule that set it, with the winner on top. Click the arrow beside the value to jump to the winning rule in the Styles pane. This is the quickest way to answer "where did this value come from?"
Testing Fixes Live
You can edit directly in the Styles pane.
- Untick a checkbox beside a declaration to turn it off and see whether the page changes.
- Click a value to edit it, or click an empty area in a rule to add a declaration.
- Use the :hov button to force
:hover,:focus, or:activeon the element. This helps when a state rule seems to be ignored.
Edits are temporary. Copy working changes back into your source files.
Fixing the Example
Do not reach for !important. Lower the winning selector or match its weight deliberately.
:where(#nav) a { color: black; }
.link { color: blue; }:where() contributes zero specificity, so the first rule becomes (0,0,1). The class rule now wins at (0,1,0). Reload and confirm that the Styles pane shows color: blue without a line through it.
Checklist When a Style Does Not Apply
- Confirm the selector matches. If the rule is missing from the Styles pane, the selector does not match or the file did not load.
- Check for a struck-through declaration and find what overrides it.
- Look for a warning icon that signals a typo or invalid value.
- Check whether an
!importantdeclaration or a cascade layer is involved. - Check for inheritance. A direct rule always beats an inherited value.
Exercise
In the Styles pane, .card { padding: 1rem; } is struck through and main .card { padding: 2rem; } is listed above it. Which rule has higher specificity, and what does the struck-through line tell you?
Show answer
main .card has specificity (0,1,1) and .card has (0,1,0), so the first wins. The line through padding: 1rem means that declaration lost the cascade and does not affect the element.