var(--gap, 16px) uses 16px if --gap isn't defined. Because variables inherit, you can scope one to a component: set --accent on a card and only that subtree changes. This local override pattern builds themeable components cleanly.
var(--gap, 16px) uses 16px if --gap isn't defined. Because variables inherit, you can scope one to a component: set --accent on a card and only that subtree changes. This local override pattern builds themeable components cleanly.
<!doctype html><html><head><meta charset="utf-8">
<style>:root{--accent:#b388ff}.card{border:2px solid var(--accent);color:var(--accent,#fff);padding:14px;margin:6px}.alt{--accent:#8aff9d}</style></head><body style="background:#06040d"><div class="card">global accent</div><div class="card alt">scoped override</div></body></html>▶ Open the interactive comic issue