SCSS Color Variables

A variable stores a color once and reuses it everywhere, so changing a brand color means editing one line instead of fifty. Name three variables and pick their colors below: the sample page recolors live, and the SCSS and the compiled CSS update next to it.

A heading in variable 1

Body text in the default color, with a link in variable 2 inside it. The button below uses variable 3 as its background.

SCSS color variables: define $color-red once and reuse it everywhere — live mini editor with three variables, a sample page, SCSS input next to compiled CSS, and a CSS custom-properties toggle.

A variable stores a color once and reuses it everywhere: $color-red: #FF0000; then h1 { color: $color-red; }. Name three variables in the demo — the sample page recolors live, and the SCSS and compiled CSS update next to it.

What SCSS is

SCSS is the main syntax of Sass, a preprocessor that adds programming features — variables, nesting, mixins — to CSS. You write a .scss file, and the Sass compiler turns it into an ordinary .css file the browser can read. Browsers do not understand SCSS directly: the .scss extension is the signal that the file needs compiling first. The standard compiler is Dart Sass; install it with npm install -g sass and compile with sass input.scss output.css. Full documentation is at sass-lang.com, and the variables reference is at sass-lang.com/documentation/variables/.

Variables: one source of truth

A Sass variable starts with $ and holds a value you reuse:

$color-red: #FF0000;
$color-blue: #2563EB;
$color-accent: #F59E0B;

h1 {
  color: $color-red;
}
a {
  color: $color-blue;
}
.button {
  background-color: $color-accent;
}

When the brand red changes, you edit one line — $color-red — and every heading, link, and button that uses it changes with it. Without variables, the same color is pasted as a literal hex code in dozens of rules, and a rebrand means hunting down every copy (and missing one, so the old red lives on in a footer somewhere). The demo above shows the same idea live: rename a variable or pick a new color and the sample page, the SCSS, and the compiled CSS all update together.

How to name variables

Literal names like $color-red are easy to read, but they go stale when the color changes — a $color-red that now holds blue is confusing. Semantic names survive rebrands: $color-primary, $color-danger, $color-accent describe the role, not the hue, so the value can change without the name lying. A common setup is both: literal variables for the palette, semantic variables built on top of them:

$red-500: #EF4444;
$color-danger: $red-500;

SCSS variables vs. CSS custom properties

Plain CSS now has its own variables — custom properties — and the demo's toggle shows the difference. SCSS variables are resolved at compile time: the compiler replaces $color-red with #FF0000 and the browser never sees the variable. CSS custom properties are resolved at run time: the browser keeps --color-red alive, so JavaScript can change it, a dark-mode rule can override it, and a user preference can flip the whole theme without recompiling. The two are not rivals — many projects use SCSS variables to define the palette and emit them as custom properties with :root { --color-red: #{$color-red}; }, getting compile-time consistency and run-time theming at once. The toggle above shows exactly that output.

SCSS variable ($…)CSS custom property (--…)
ResolvedAt compile timeAt run time, in the browser
Changeable by JSNoYes
Dark mode / themingNeeds a recompileOverride in a @media rule
Works in plain CSSNo — needs SassYes — native CSS

Scope and imports

Variables defined at the top level of a file are global; variables defined inside a rule are local to that rule. In modern Sass, files are loaded with @use (which namespaces the variables, so you write colors.$color-red) rather than the old @import, which dumped everything into one global scope. If you are starting a new project, use @use — it is the current standard, and @import is deprecated.

Frequently asked questions

What is an SCSS color variable?

A variable in SCSS (Sass) that stores a color once and reuses it: $color-red: #FF0000; then h1 { color: $color-red; }. Change the variable and every rule that uses it changes too.

Do browsers understand SCSS variables?

No. SCSS is compiled to plain CSS first — the Sass compiler replaces $color-red with #FF0000, and the browser only ever sees the compiled CSS. If you need variables the browser itself understands, use CSS custom properties instead: :root { --color-red: #FF0000; } and color: var(--color-red);.

What is the difference between SCSS variables and CSS custom properties?

SCSS variables are resolved at compile time and cannot be changed by JavaScript or a dark-mode rule; CSS custom properties are resolved at run time in the browser, so they can be themed and changed live. Many projects use both: SCSS variables define the palette, custom properties expose it to the browser.

What file extension do SCSS files use?

The .scss extension — for example, styles.scss. Browsers cannot read .scss files, so the file must be compiled to .css with the Sass compiler (sass input.scss output.css) before it is used on a page.

How should I name color variables?

Prefer semantic names that describe the role — $color-primary, $color-danger, $color-accent — over literal names like $color-red, because the value can change in a rebrand without the name lying. Keep literal names for the raw palette underneath.

Related tools

Tutorials · CSS Color Basics · CSS Text Color · CSS Background Color · HTML Text Color · Color Converter