Don't.
You are still here, so I guess you were expecting a more detailed explanation... here it goes:
The use of !important is considered an an...
For further actions, you may consider blocking this person and/or reporting abuse
I agree that there are some cases in which
!important
could be interesting (and it will most definitely need to be used in the user-defined styles to override the ones from the site). But from an accessibility perspective, the idea of immutability (from the developer side) is dangerous, as it takes away power from the users to customize the experience to better fit their needs. Let me recheck the article, and I'll edit and add a note about it.I believe there is no valid use cases for
!important
. Your suggestions on the alternatives are top-notch, and following these usually makes your code cleaner.You've clearly never built an HTML email :) inline styles for Outlook so need to use
!important
to overwrite them... horrible but in this case necessary.inline styles will replace !important
I learnt this by the video trivia by web dev simplified and kevin powell!
And kevin as a CSS Mastermind lost to this question... Very bad!
But, Kevin is the CSS Master!
Wait...
!important
will trump inline styles 🤔You made me doubt for a second, so I created an example of it for another comment:
!important
does override inline styles.Actually I expect custom origins/cascade layers to eventually replace most !important use. But it'll be some years before we can use them.
Look I'm not saying that
!important
is a dangerous anti-pattern, but in 10 years developing websites as my main revenue source the only times I've had to use it is when someone else used it before (by example in a WordPress theme, if I had to pick at random).I get the point of your article about utility classes being all alone and depraved of specificity thus needing a bit of help from
!important
but that is so edge case, it should definitely be a last resort after you've exhausted your other last resort options.Important is not bad it's the situation that leads to this being used that's bad. In a JavaScript context it has some uses I suppose.
After seeing the title I was hoping so hard for this first paragraph to be there, thank you for making my dreams true.
Agree however I do use !important a fair bit in the work I do with HTML emails because Outlook..., but I tend to avoid in anything else.
Sometimes you need to apply styles to elements abstractly so you can't get specific with your selectors.
Also online styles will override !important if you add !important to the online style itself.
When I find elements that are too generic to style, I normally solve it by adding a class/id to the elements or one of their ancestors, which allows for easier and more specific selectors. Do you have an example of applying styles to elements abstractly and how did you fix it with
!important
?Also, inline styles do not override
!important
as it can be seen in this example:Right i actually meant inline with !importa overrides styleseet !important
Hahaha, your "You are still here...", it is so cute 🤣