CSS specificity problems appear when a declaration exists in the stylesheet but a different rule controls the rendered element. The browser chooses the final value through the cascade, so debugging starts with the rule that actually wins instead of adding heavier selectors until the page changes.
Specificity compares selector weight in three columns, counting IDs, classes and similar selectors, then element types. A two-class selector beats a one-class selector even when the one-class rule appears later. Origin, importance and cascade layers are considered before that comparison, so a heavier selector cannot solve every override.
A text editor provides an editable page, while Chrome DevTools exposes its matching rules and crossed-out declarations. Lowering an overly specific base rule lets a primary-button class override it without !important. The change belongs in the stylesheet because ordinary DevTools edits disappear on reload.
Steps to debug CSS specificity:
- Create specificity.html in a folder of your choice with the following button markup.
- specificity.html
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>CSS specificity</title> <link rel="stylesheet" href="styles.css"> </head> <body> <section class="pricing-card"> <h1>Pricing</h1> <button class="button button-primary">Choose plan</button> </section> </body> </html>
- Create styles.css beside specificity.html with the following competing rules.
- styles.css
body { font: 18px sans-serif; margin: 16px; } h1 { font-size: 26px; margin: 0 0 12px; } .pricing-card { background: #f1f5f9; padding: 16px; } .pricing-card .button { background: #0f172a; color: white; border: 0; padding: 12px 20px; font: inherit; } .button-primary { background: #0f766e; }
The primary class requests teal, but the component rule requests dark navy for the same button.
- Open the saved specificity.html file in Chrome.

- Inspect the Choose plan button with the context menu's Inspect command.

- Compare the two background declarations in Elements → Styles.
The dark button matches the winning #0f172a declaration. The teal #0f766e declaration is crossed out. .pricing-card .button has specificity 0-2-0; .button-primary has 0-1-0. Both are normal author rules in the same layer, so the two-class selector wins despite appearing earlier.
On an existing page, an inline style, !important or a different cascade layer can explain an override before specificity matters. A missing rule may instead mean the selector does not match or the stylesheet did not load.
Related: How to set CSS cascade layer order - Replace the selector .pricing-card .button in styles.css with :where(.pricing-card) .button.
:where(.pricing-card) .button { background: #0f172a; color: white; border: 0; padding: 12px 20px; font: inherit; }
The declarations and the later .button-primary rule stay unchanged. :where(.pricing-card) still limits the match to the card, but contributes zero specificity. Both button rules now have 0-1-0, so the later primary rule wins. Unlike :where(), :is(), :not() and :has() take the highest specificity from their selector arguments.
- Save styles.css in your text editor.
- Reload specificity.html in Chrome.

- Confirm that the button is teal with .button-primary controlling background in Styles.
The primary rule now shows #0f766e without a strike-through, while the base rule's #0f172a is crossed out. If the button stays dark, an unsaved stylesheet or a different winning rule will still be visible in Styles.