Skip to content

Dangerous: !important

I’m no expert in CSS but I do know that using !important excessively is dangerous. A lazy developer would use !important to force it to look like something. I call them lazy because they refuse to use the point system. Instead of making the selectors more specific, they just use !important. When adding a style and it didn’t work, !important is not your only option.

!important should be your very last option. It’s dangerous to use it whenever because another developer might get confused on why his newly defined property is not working. Only to find out after that it got overwritten because of a previously stated property with !important. And that !important wins out all the time, regardless if you make yours very specific. It’s a bully, really.

.date {
width: 20px !important;
color: #fff !important;
background color: #000 !important;

Lazy solution. Why not try this?

.post .date {
width: 20px;
color: #fff;
background color: #000;

Most of the time, the reason why a style doesn’t work is because something else is defining its style. And it’s probably had more points so it wins. Don’t try to beat it with a hack like !important.

I’d rather be specific with my css selectors than use !important profusely. This way, I’m sure I’m only changing what I want to change.

For reference, if you want to learn more about CSS Specificity, click here.

One Comment

  1. Rod Rod

    Wow! mas malakas pa pala !important kaysa sa style=”XXXX”!

Leave a Reply

Your email address will not be published. Required fields are marked *