Importance and inline styles
Definition and purpose
The importance annotation !important changes the cascade priority of a declaration. An inline style is an author declaration attached directly to an element. A normal inline declaration wins over ordinary normal author selector rules, but an important author rule can override it.
Normal inline precedence
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style>p { color: green; }</style> </head> <body> <p id="a" style="color: navy">Inline</p> <p id="b">Rule</p> </body></html>The inline normal declaration wins for a.
Syntax and mental model
Write color: green !important; with the annotation after the value. In the ordinary author context, an important inline declaration outranks other important author rules. Important user and user-agent origins outrank important author declarations; active transitions have higher cascade priority still. Layers also affect important priority and are taught later. These fixtures isolate ordinary author declarations.
Importance before specificity
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style>p { color: green !important; }</style> </head> <body> <p id="a" style="color: navy">Inline</p> <p id="b" style="color: navy !important">Important inline</p> </body></html>The rule overrides normal inline color but not important inline color.
Common mistakes
Avoid making every declaration important: it obstructs routine overrides. Prefer removing an unnecessary inline style or restructuring the component. Never claim important beats everything.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: CSS-wide keywords. Next lesson: Value types and grammar basics.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Importance and inline styles — knowledge check
Five questions on importance and inline styles.
Where is !important placed?
What wins: normal inline color or normal author ID rule?
Can an important author rule override normal inline color?
What wins between an important inline author color and an important ordinary author color?
Why avoid unnecessary important declarations?