freecoding.school100% FREE · NO SIGNUP
Neon DistrictISSUE #7 of 50

variables · custom properties · --var

PrismaVSJank the Janitor
Prisma saysCustom properties (CSS variables) store reusable values, declared with -- and read with var().

Declare a variable like --accent: #b388ff (commonly on :root) and use it anywhere with var(--accent). Change it once and everything updates. Unlike preprocessor variables, these are live in the browser, cascade and inherit, and can be read/changed by JavaScript at runtime — the basis of theming.

Power-ups you unlock

Jank the Janitor attacks — common mistakes

Boss battleDefine --accent on :root, use it in three rules, then change it and watch all update.

Example code

<!doctype html><html><head><meta charset="utf-8">
<style>:root{--accent:#b388ff}h1{color:var(--accent)}button{border:1px solid var(--accent);color:var(--accent);background:none;padding:8px 14px}</style></head><body style="background:#06040d"><h1>themed by a variable</h1><button>same accent</button></body></html>
▶ Open the interactive comic issue
‹ Animation Events · Animationstart · AnimationendVar() · Fallback · Scoping ›