Today i wrote a whole stylesheet filled with '!important' rules.
For each rule i wrote i carry a technical debt, The moment someone asks me to revisit this rules i'll be paying a part of that debt.
- I have to find the old rules and remove it, it's a dead load now — doing so is very time consuming. ( payback - Time wasted )
- I have to keep track of the order of each rule and the specificity of the selectors to determine which rule will be applied — Awful experience filled with frustration, You'll lose your mind. ( payback - Time, Energy )
- In most cases i won't be able to re-use existing rules so i'll be adding a couple of importants ( payback - Time, code quality )
" And losing Time, Energy and Quality, is the exact opposite of development "
What you should be doing instead is to re-use the rules you're writing, do DRY coding — Don't repeat yourself, also maintain a modular structure to be able to revisit your rules anytime and modify them with ease.
Of course you you'll find cases when you should be using !important,
In my opinion there are two cases:
- To change the state of an element temporarily
- Someone has left his debt for you to pay and you can't say no, Then do it until you find a better job :)