Questions And Answers

More Tutorials

CSS !important declaration

The !important declaration is used to override the usual specificity in a style sheet by giving a higher priority to a rule.

Its usage is: property : value !important;


#mydiv {
font-weight: bold !important; /* This property won't be overridden
by the rule below */

#outerdiv #mydiv {
font-weight: normal; /* #mydiv font-weight won't be set to normal
even if it has a higher specificity because
of the !important declaration above */

Avoiding the usage of !important is strongly recommended (unless absolutely necessary), because it will disturb the natural flow of css rules which can bring uncertainty in your style sheet. Also it is important to note that when multiple !important declarations are applied to the same rule on a certain element, the one with the higher specificity will be the ona applied.

Here are some examples where using !important declaration can be justified:

  • If your rules shouldn't be overridden by any inline style of the element which is written inside style attribute of the html element.
  • To give the user more control over the web accessibility, like increasing or decreasing size of the font-size, by overriding the author style using !important.
  • For testing and debugging using inspect element.


In this page (written and validated by ) you learned about CSS !important declaration . What's Next? If you are interested in completing CSS tutorial, your next topic will be learning about: CSS specificity.

Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue:

Share On:

Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using, you agree to have read and accepted our terms of use, cookies and privacy policy.