Can I override inline !important?

Jeffrey Basurto picture Jeffrey Basurto · Jun 22, 2012 · Viewed 103.1k times · Source

If you have

<div style="display: none !important;"></div>

Is there a way to override that in the style sheet to make it displayed?

Preferably using something similar to this:

div { display: block !important; }

Answer

Oleg picture Oleg · Jun 22, 2012

Let me begin by saying that generally inline styles can be overridden:

.override {color:red !important;}
<p style="color:blue;">I will be blue</p>
<p style="color:blue;" class="override">But I will be red</p>

This behavior is described in W3 specs, where it is stated that !important declarations do not alter the specificity, but rather take precedence over "normal" declarations.

That being said, when conflicting rules both have the !important flag, specificity dictates that an inline rule is applied - meaning that for OP's scenario, there's no way to override an inline !important.