Skip to content

Commit e6233c7

Browse files
authored
Add recommendation to avoid using !important
This recommendation was adopted internally to align with our infrastructure conformance checks and best practices. While !important is a legitimate feature of CSS, its use increased complexity and maintenance costs when styles were reused and shared across multiple projects.
1 parent 8d4a22b commit e6233c7

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

htmlcssguide.html

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,27 @@ <h4 id="Hexadecimal_Notation" class="numbered">Hexadecimal Notation</h4>
693693
color: #ebc;
694694
</code></pre>
695695

696+
<h4 id="Important_Declarations" class="numbered">Important Declarations</h4>
697+
698+
<p>Avoid using <code>!important</code> declarations.</p>
699+
700+
<p>These declarations break the natural cascade of CSS and make it difficult to
701+
reason about and compose styles. Use
702+
<a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity">selector specificity</a>
703+
to override properties instead.</p>
704+
705+
<pre><code class="language-css bad">/* Not recommended */
706+
.example {
707+
font-weight: bold !important;
708+
}
709+
</code></pre>
710+
711+
<pre><code class="language-css good">/* Recommended */
712+
.example {
713+
font-weight: bold;
714+
}
715+
</code></pre>
716+
696717
<h4 id="Hacks" class="numbered">Hacks</h4>
697718

698719
<p>Avoid user agent detection as well as CSS “hacks”—try a different approach
@@ -713,8 +734,8 @@ <h4 id="Declaration_Order" class="numbered">Declaration Order</h4>
713734

714735
<p>Alphabetize declarations.</p>
715736

716-
<p>Put declarations in alphabetical order in order to achieve consistent code in a
717-
way that is easy to remember and maintain.</p>
737+
<p>Put declarations in alphabetical order in order to
738+
achieve consistent code in a way that is easy to remember and maintain.</p>
718739

719740
<p>Ignore vendor-specific prefixes for sorting purposes. However, multiple
720741
vendor-specific prefixes for a certain CSS property should be kept sorted (e.g.

0 commit comments

Comments
 (0)