From e6233c7428f061498e71827ccefe9d0c72084ad5 Mon Sep 17 00:00:00 2001 From: Tony Ruscoe Date: Thu, 13 Jan 2022 14:29:39 +0000 Subject: [PATCH] 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. --- htmlcssguide.html | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/htmlcssguide.html b/htmlcssguide.html index 8bab67a6e..ba283fea2 100644 --- a/htmlcssguide.html +++ b/htmlcssguide.html @@ -693,6 +693,27 @@

Hexadecimal Notation

color: #ebc; +

Important Declarations

+ +

Avoid using !important declarations.

+ +

These declarations break the natural cascade of CSS and make it difficult to +reason about and compose styles. Use +selector specificity +to override properties instead.

+ +
/* Not recommended */
+.example {
+  font-weight: bold !important;
+}
+
+ +
/* Recommended */
+.example {
+  font-weight: bold;
+}
+
+

Hacks

Avoid user agent detection as well as CSS “hacks”—try a different approach @@ -713,8 +734,8 @@

Declaration Order

Alphabetize declarations.

-

Put declarations in alphabetical order in order to achieve consistent code in a -way that is easy to remember and maintain.

+

Put declarations in alphabetical order in order to +achieve consistent code in a way that is easy to remember and maintain.

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