src/content/docs/linter/rules/no-important-styles.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="CSS" icon="seti:css"> ## Summary - Rule available since: `v2.0.0` - Diagnostic Category: [`lint/complexity/noImportantStyles`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule has an [**unsafe**](/linter/#unsafe-fixes) fix. - The default severity of this rule is [**warning**](/reference/diagnostics#warning). - Sources: - Same as [`declaration-no-important`](https://github.com/stylelint/stylelint/blob/main/lib/rules/declaration-no-important/README.md){
"linter": {
"rules": {
"complexity": {
"noImportantStyles": "error"
}
}
}
}
Disallow the use of the !important style.
The !important CSS style is a declaration used to give a specific rule
higher precedence over other conflicting rules. When it is applied to a CSS
property, that property's value is prioritized over any other declarations,
regardless of specificity or order of appearance in the stylesheet.
!important Works!important to a rule overrides this cascade logic, forcing the
rule to apply even if other rules have higher specificity or are defined later.!important Should Be AvoidedWhile !important can solve specific and immediate styling issues, its effects
can result in long-term problems within a codebase:
!important is used in a stylesheet, other developers
may respond by using it even more aggressively, creating a cycle of overrides and
increasing maintenance difficulty.!important rule overriding expected behavior..style {
color: red !important;
}