Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When a CSS declaration does not take effect, do not immediately add a longer selector or !important. Check that the rule matches the element, inspect the browser’s computed value, and then identify which cascade criterion lets the competing declaration win. A later rule is only decisive when the earlier cascade criteria are tied.

What a CSS style override means

The CSS cascade selects a value for each property when more than one applicable declaration could set it. The beginner shorthand—source order, specificity, and importance—is useful, but it is not the complete modern decision process. The browser first considers whether a declaration is relevant, then resolves origin and importance, cascade layers, specificity, scoping proximity where applicable, and finally order of appearance when earlier criteria tie. Animations and transitions also have special precedence in the cascade. MDN’s cascade guide explains the full ordering.

This means “put my rule later” or “make my selector more specific” is not a universal fix. Specificity only decides between declarations that are tied on the criteria ahead of it.

How to find why a CSS declaration is losing

  1. Inspect the exact property. In browser developer tools, select the affected element and look at the computed value for the property that is wrong. This shows the value the browser actually uses, rather than only the declaration you intended to apply.
  2. Confirm the rule applies. Check that the selector matches the element and that the stylesheet and declaration are active. A declaration that does not apply cannot win the cascade.
  3. Identify the competing declaration. In the matched-rules view, find other declarations for the same property and note where they come from, whether they are marked !important, and whether they are in cascade layers.
  4. Compare cascade priority in order. Resolve origin and importance first, then layer order, specificity, scoping proximity when scoped rules are involved, and source order if the preceding criteria tie. If the property is animated or transitioning, account for that special precedence too.
  5. Change the cause, not just the symptom. Edit the declaration that supplies the unwanted value where possible. If both rules are yours, use intentional layer organization, appropriate source order, or a narrowly scoped selector rather than escalating specificity without understanding the conflict.

How do I override inline CSS with a class?

A normal class rule in an author stylesheet generally loses to a normal inline declaration on the same element. Increasing the class selector’s ordinary specificity does not make it a universal override: inline declarations are not simply an ordinary selector with an arbitrarily large specificity score.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

First check whether the inline value can be removed or changed at the code that generates it. That is usually the cleanest solution. If you cannot change its source, assess the complete cascade before considering an important declaration. An author-origin !important declaration can beat a normal inline author declaration, but competing important declarations from other origins and transitions can change the result. !important is therefore not a guaranteed fix for every inline-style conflict.

When to use !important—and when not to

!important changes cascade priority; it is not just a way to make a selector “more specific.” Use it only when the intended priority is deliberate, such as a narrowly scoped utility or a necessary override of a third-party declaration. Document why it is needed so a future contributor can understand the exception.

Widespread important declarations make conflicts harder to debug and maintain. They can also make it harder for users to apply their own styles for readability or accessibility. Before adding one, verify that the competing rule cannot be corrected at its source or managed through a clearer layer or component boundary.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose an override that remains maintainable

  • Best when you control the source: change or remove the declaration that creates the unwanted value, especially an inline value generated by application code.
  • Best when both rules are yours: organize rules into intentional cascade layers, or adjust source order when the earlier cascade criteria tie.
  • Useful for component styling: use a selector scoped to the actual component relationship, without adding unrelated selector weight.
  • Use sparingly: reserve !important for a documented, limited exception after confirming the relevant origins, layers, and other cascade behavior.

For a concise beginner framing of source order, specificity, and importance, see Quang Nguyen’s 2021 article on the CSS style override technique. Its three concepts are a starting point; use the fuller cascade ordering above when those basics do not explain the result.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.