CSS Tutorial

The language for styling web pages.

CSS Variables

CSS Variables (Custom Properties)

CSS variables (also called custom properties) allow you to store values that can be reused throughout your stylesheet. They are defined with -- prefix and accessed with var().

Syntax:

:root { --primary: #1572B6; }
.element { color: var(--primary); }

Benefits:

  • Reusable values across the stylesheet
  • Easy to update (change one place = changes everywhere)
  • Can be changed with JavaScript
  • Supports theming (light/dark mode)

Try It Yourself

Edit the code below and click Run to see the result live.

Source Code
Result
Topics