// origin$best-color: hsl(322, 92%, 24%);// meaning$action: $best-color;// usage$link: $action;$button: $action;
$colors: ( 'brand-blue': hsl(195, 52%, 31%), 'brand-orange': hsl(24, 100%, 62%), 'brand-pink': hsl(322, 92%, 24%),);html { @for $name, $value in $colors { --#{$name}: #{$value}; }}
❌ Browser Fallbacks button { background: teal; /* old browser */ /* empty variables */ background: var(--btn-color, var(--action, teal));}
Browser Fallbacks html { background: red; }@supports (--css: variables) { html { background: green; }}
[attr] ➡ Presence (even if empty) [attr="..."] ➡ Exact match [attr*="..."] ➡ Any match [attr~="..."] ➡ Space-delimited (like classes) [attr|="..."] ➡ Hyphen-delimited [attr^="..."] ➡ Starts with… [attr$="..."] ➡ Ends with… [attr="..." i|s] ➡ Case sensativity
Hue is Radial * { --complement: calc(var(--h) - 180); background: hsl(var(--complement), var(--s), var(--l));}
Lightness is “Clamped” * { --threshold: 55; --contrast: calc((var(--l) - var(--threshold)) * -100%); color: hsl(var(--h), var(--s), var(--contrast));}
Specified Value Cascaded or Defaulted color: currentColor; - cascaded display: block - cascaded (from UA) font-family - inherited (from parent) background-color: transparent - initial (from spec)
html { --color: green; --color: initial; background: initial; background: var(--color, red); /* ??? */}
Computed Value Relative values and variables are replaced color: currentColor » rgb(0, 0, 0) padding: 2em » ( * 2) » 48px (for example)
Used Value Final resolutions, based on layout etc width: 80% » 1223px (for example) color-scheme: dark light » dark (for example) flex: 1 » (nothing on non-flex items)
html { @media (prefers-color-scheme: dark) { --os-mode: -1; } @media (prefers-color-scheme: light) { --os-mode: 1; }}
<div style="--index: {{ loop.index }};"> [style*='--index'] { animation-delay: calc(var(--index) * 50ms);}
<div style="--ease: var(--in-out-back);"> [style*='--ease'] { --in-quad: cubic-bezier(0.55, 0.085, 0.68, 0.53); --out-quad: cubic-bezier(0.25, 0.46, 0.45, 0.94); --in-out-back: cubic-bezier(0.68, -0.55, 0.265, 1.55);}
<section class="sprite-demo" :style="{ '--src': show.sprite.src, '--columns': show.sprite.columns, '--rows': show.sprite.rows,}">...</section>
<div v-for="action in show.actions" :key="action.name" :data-action="action.name" :style="{ '--row': action.row, }"/>
button { --color: green; background: var(--color); transition: background 0.5s; &:hover { --color: red; }}
Current JavaScript CSS.registerProperty({ name: "--brand-color", syntax: "<color>", initialValue: "pink", inherits: true,});