codegurukool.com · Free coding tutorials & online compiler

Home › CSS Tutorial › CSS variables

CSS variables

Reusable custom properties.

Define with --name (usually on :root) and read with var(--name,fallback). Change one value to re-theme everything.

Example code

<style>
:root{--main:#e4572e;--pad:14px}
.a{background:var(--main);padding:var(--pad);color:#fff}
.dark{--main:#14213d}
</style>
<div class='a'>Default</div><div class='a dark'>Overridden variable</div>

Run this code in the online editor

← Multiple columnsFlex container →