Last Updated: February 25, 2016
·
1.144K
· georgiee

forget !important

Working through a big set of external css styles I just see plenty of !important statements. Forget the !important statement! Period.

It`s your laziness which requires the use of "important". I can't remember ANY situation where I had to use the important statement. When you use !important you make the hierarchical order of your css statements unpredictable and your life harder.
Enjoy your day!

4 Responses
Add your response

CSS selectors are classified according to his significance so a selector which selected an element by ID has an higher significance as a selector which only selected an element by a class. In the case of when the significance is the same and you don´t want/can change the data you must use the !important statement i.e third party plugins which dont´t know the environment.

But you´re right the use of !important make the hierarchical order of your css statements unpredictable and less elegant.

over 1 year ago ·

@becreative-germany thanks for the reply. I know about the theoretical use but it is so rare that it would be better never to tell beginners about !important. The would get their own ways. For example by prepending their element definition with a parent element or another class to increase the significance. Even if they would create elements with ids to get that significance- still better than using that annoying and lazy !important way

over 1 year ago ·

Georgiee I agree with your reply but there is just times where there is no other option, I have found myself in cases where I have to work with a js or css files that I cannot get rid of and the only option is go with an !important so more than saying "forget import" I think is about been wise using it.

over 1 year ago ·

I'm sorry I don't agree. Using !important should always be a last resort but sometimes it can't be helped. I occasionally come across the unavoidable working on large scale dynamic websites, I ALWAYS try to find an alternative and reconfigure the specificity but sometimes the means justifies the ends, this especially true when the code is being passed onto another developer at some point. Forcing a goose-chase type workaround with specificity can be just as detrimental as using !important.

I also don't believe it shouldn't be taught to beginners. Once they figure out that it exists they will use it thinking it's a natural path of their learning, much like JavaScripts eval() method.

over 1 year ago ·