HTML & CSS Masterclass Tutorial

Comprehensive guide to modern HTML and CSS development.

Custom Properties

CSS Variables (Custom Properties)

CSS Variables allow you to store specific values (like colors, fonts, or sizes) in one place and reuse them throughout your entire stylesheet.

Why use CSS Variables?

  • Maintainability: If you want to change your brand's primary color, you only change the variable value once, and the whole site updates.
  • Theming: Makes implementing Light/Dark mode incredibly easy by just swapping the variable values.

Variables are defined with a double hyphen -- inside the :root selector, and called using the var() function.

Try It Yourself

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

Source Code
Result
Topics