{"id":6703,"date":"2025-08-05T14:33:43","date_gmt":"2025-08-05T19:33:43","guid":{"rendered":"https:\/\/frontendmasters.com\/blog\/?p=6703"},"modified":"2025-08-05T14:33:44","modified_gmt":"2025-08-05T19:33:44","slug":"little-reminder-about-custom-properties-with-invalid-values","status":"publish","type":"post","link":"https:\/\/frontendmasters.com\/blog\/little-reminder-about-custom-properties-with-invalid-values\/","title":{"rendered":"Little Reminder About Custom Properties with Invalid Values"},"content":{"rendered":"\n<p>This is like one of those weirdly difficult quizzes about CSS. If you&#8217;ve got a <code>&lt;p><\/code> element sitting there in a totally normal basic HTML layout, then this CSS:<\/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\">html<\/span> {\n  <span class=\"hljs-attribute\">--color<\/span>: blah;\n}\n<span class=\"hljs-selector-tag\">body<\/span> {\n  <span class=\"hljs-attribute\">color<\/span>: blue;\n}\n<span class=\"hljs-selector-tag\">p<\/span> {\n  <span class=\"hljs-attribute\">color<\/span>: green;\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-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>What color does the <code>&lt;p><\/code> render as?<\/p>\n\n\n\n<p><a href=\"https:\/\/codepen.io\/editor\/chriscoyier\/pen\/zxvZPvr\">It&#8217;s <code>blue<\/code><\/a>. You might think it&#8217;s <code>green<\/code>, as the value <code>blah<\/code> is an invalid color. If the CSS had&#8230;<\/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\">p<\/span> {\n  <span class=\"hljs-attribute\">color<\/span>: green;\n  <span class=\"hljs-attribute\">color<\/span>: blah;\n}<\/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>&#8230; then indeed it <em>would<\/em> be <code>green<\/code>. But CSS can&#8217;t know (in time) that the custom property is invalid, so it falls back to inheritance, which makes it <code>blue<\/code> from the body. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is like one of those weirdly difficult quizzes about CSS. If you&#8217;ve got a &lt;p> element sitting there in a totally normal basic HTML layout, then this CSS: What color does the &lt;p> render as? It&#8217;s blue. You might think it&#8217;s green, as the value blah is an invalid color. If the CSS had&#8230; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":6704,"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":[29],"tags":[7,180],"class_list":["post-6703","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-the-beat","tag-css","tag-custom-properties"],"acf":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2025\/08\/pexels-photo-27597532.jpeg?fit=975%2C1300&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/6703","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=6703"}],"version-history":[{"count":1,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/6703\/revisions"}],"predecessor-version":[{"id":6705,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/6703\/revisions\/6705"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media\/6704"}],"wp:attachment":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media?parent=6703"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/categories?post=6703"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/tags?post=6703"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}