GamutDesk Logo
GamutDesk

CSS :root Custom Properties Generator

Create a CSS :root block of color custom properties like --color-primary: #3B82F6. Name your colors, set a prefix and copy production-ready CSS.

Client-Side ArchitecturePrivate Client-Side Processing

Colors (5/12)

Output

CSS (:root)
:root {
  --color-primary: #2563EB;
  --color-secondary: #7C3AED;
  --color-success: #16A34A;
  --color-warning: #F59E0B;
  --color-surface: #F8FAFC;
}

Technical Specification & Mathematical Principles

How the CSS Variables Generator Works

CSS custom properties are declared with a double-dash name inside a selector, and :root targets the html element so the values cascade through the whole document. They are read with var(--color-primary) and, unlike preprocessor variables, can change at runtime and be overridden per component or per theme.

The generator lowercases names, replaces unsupported characters with hyphens, adds an optional prefix and normalizes every value to uppercase #RRGGBB. Duplicate names get numeric suffixes so no property is silently overwritten.

Frequently Asked Questions

Why prefix variables with --color-?
A prefix groups related tokens and avoids clashes with other custom properties, such as spacing or font tokens, in a large codebase.
Can I switch themes with these variables?
Yes. Redeclare the same properties under a selector such as [data-theme="dark"] or inside @media (prefers-color-scheme: dark), and every var() reference updates.
Are custom properties case-sensitive?
Yes. --Color-Primary and --color-primary are different properties, so the generator always emits lowercase names.

Related Design & Color Instruments