Search code examples
htmlcssspecifications

Where is the CSS spec that says the "!important" takes precedence over inline element styles?


In all modern browsers, CSS rules declared with the !important keyword take precedence over all other declarations, even including those made inside the element style attribute.

Where in the CSS spec does it say it should override element style attribute rules? I am trying to find it here but am not having any luck:

https://www.w3.org/TR/css-cascade-5/#importance

I really don't like that it overrides element styles, and am wondering if this behavior was even in the specs to begin with.


Solution

  • Right at the top of the section on the cascade sort

    The cascade sorts declarations according to the following criteria, in descending order of priority:

    The very first entry is:

    Origin and Importance

    which includes all the !important rules.

    The third entry is:

    Element-Attached Styles