{"id":8128,"date":"2026-01-01T11:20:06","date_gmt":"2026-01-01T16:20:06","guid":{"rendered":"https:\/\/frontendmasters.com\/blog\/?p=8128"},"modified":"2026-01-01T11:22:11","modified_gmt":"2026-01-01T16:22:11","slug":"important-and-css-custom-properties","status":"publish","type":"post","link":"https:\/\/frontendmasters.com\/blog\/important-and-css-custom-properties\/","title":{"rendered":"!important and CSS Custom Properties"},"content":{"rendered":"\n<p>This just bit me the other day so I&#8217;m going to write it down. Again, as it&#8217;s <a href=\"https:\/\/css-tricks.com\/the-surprising-behavior-of-important-in-css-custom-property-values\/\">surprised me before<\/a>. I just think I can maybe explain it even more clearly this time.<\/p>\n\n\n\n<p>CSS custom properties are super permissive in what values are valid. Like this is totally fine, and I sure it can get much weirder:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">--whats-up<\/span>: (\ud83d\udc4d\ud83c\udffb\u1d17 _\u1d17)\ud83d\udc4d\ud83c\udffb;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>So my brain extends that to think that <em>this also<\/em> is a complete valid value:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">--color<\/span>: <span class=\"hljs-selector-tag\">orange<\/span> !<span class=\"hljs-selector-tag\">important<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Like the value of <code>--color<\/code> is <code>orange !important<\/code>;<\/p>\n\n\n\n<p>But it&#8217;s not! The value is just <code>orange<\/code> and the declaration itself is &#8220;important&#8221;. Hopefully this graphic makes it even more clear:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"860\" src=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2026\/01\/Screenshot-2026-01-01-at-7.11.02-AM.png?resize=1024%2C860&#038;ssl=1\" alt=\"A graphic explaining CSS custom properties, highlighting the difference between the value and the declaration, with emphasis on the statement '--color: orange !important;' and clarifications in colorful text.\" class=\"wp-image-8135\" style=\"aspect-ratio:1.1907126830866968;width:718px;height:auto\" srcset=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2026\/01\/Screenshot-2026-01-01-at-7.11.02-AM.png?resize=1024%2C860&amp;ssl=1 1024w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2026\/01\/Screenshot-2026-01-01-at-7.11.02-AM.png?resize=300%2C252&amp;ssl=1 300w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2026\/01\/Screenshot-2026-01-01-at-7.11.02-AM.png?resize=768%2C645&amp;ssl=1 768w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2026\/01\/Screenshot-2026-01-01-at-7.11.02-AM.png?w=1410&amp;ssl=1 1410w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/figure>\n<\/div>\n\n\n<p>This can come up when there are multiple declarations that apply to the same element. Normally specificity and source order help sort out which declaration wins, but just as <code>!important<\/code> always does, an <code>!important<\/code> declaration trumps those other things. <\/p>\n\n\n\n<p>So say you have a:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"greeting\"<\/span>&gt;<\/span>Hello<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Then two selector blocks:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">div<\/span> {\n  <span class=\"hljs-attribute\">--color<\/span>: red <span class=\"hljs-meta\">!important<\/span>;\n}\n\n<span class=\"hljs-selector-class\">.greeting<\/span> {\n  <span class=\"hljs-attribute\">--color<\/span>: blue;\n  <span class=\"hljs-attribute\">color<\/span>: <span class=\"hljs-built_in\">var<\/span>(--color);\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Even though <code>--color<\/code> is set to <code>blue<\/code> right there next to where it is used with a higher-specificity selector, <a href=\"https:\/\/codepen.io\/editor\/chriscoyier\/pen\/019b4d34-06d2-7bbb-9e68-f0816d7d7580\">the greeting will actually be <code>red<\/code><\/a>. If <code>!important<\/code> became part of the value, <code>blue<\/code> would have won because the custom property declaration is more specific and would have won. But it&#8217;s the custom property declaration itself that is important-ized and thus the <code>red<\/code> value wins.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The `!important` part doesn&#8217;t become part of the value, the whole declaration is treated as !important;<\/p>\n","protected":false},"author":1,"featured_media":8137,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[432,7,180],"class_list":["post-8128","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog-post","tag-important","tag-css","tag-custom-properties"],"acf":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2026\/01\/Screenshot-2026-01-01-at-7.22.24-AM.png?fit=1540%2C1026&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/8128","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/comments?post=8128"}],"version-history":[{"count":5,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/8128\/revisions"}],"predecessor-version":[{"id":8141,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/8128\/revisions\/8141"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media\/8137"}],"wp:attachment":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media?parent=8128"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/categories?post=8128"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/tags?post=8128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}