Is it allowed to use !important in CSS theme files?

Is it allowed to use !important in CSS theme files?

No, it’s not allowed. You need to either add all of the CSS files into one style.css file or import them one by one ( If it’s WordPress wp_enqueue_style() for all files )

I know that I am talking if I can add !important in a class or id.

ex:

.my-class{
display: none !important;
}

Yes, you can use !important property in your CSS.

Thank you.

Why do you give this stupid answeres without reading the question correctly, this is not the first time I get this type of response from you!

Allowed or no, it is not a good practice. You should write your CSS in a way the !important should never be needed.
The only case where it is ok is to override some 3rd party CSS (from 3rd party plugin/library you are using) which cannot be overridden in a more “clean” way.
But if you are using it to override your own CSS, you are doing something wrong.

1 Like

I checked some them3s and all of them use !important, sometltimes is necessary.

Maybe it’s your luck that you’re getting stupid answers from me but this was on me, I read the question wrong. The answer is for @import instead of !important;

As you can use it but make sure it’s not too much.

As the above Authors already suggested you that you can use but you should avoid to use the !important for overriding your own template/theme css rules. You can use only when it is really need for your design. It is not a requirement that you can’t use but should avoid as far you can.

Thanks