CSS Variable Generator

Design complete color theme systems using CSS custom properties with automatic shade generation and dark mode support.

About This Tool

The CSS Variable Generator is a free browser-based tool for designing complete color theme systems using CSS custom properties (also known as CSS variables). Instead of manually calculating shade variations and writing repetitive :root declarations, this tool automates the entire workflow — from defining base colors to generating a full palette with semantic token mappings and dark mode variants.

Start by adding named colors with a visual color picker or hex input. The tool automatically generates 11 shade variations (50 through 950) for each base color using HSL lightness manipulation, similar to how Tailwind CSS and Material Design build their color scales. You can then assign colors to semantic roles like background, surface, text, primary, success, and error — creating a design token layer that decouples your component styles from specific color values.

Three variable naming conventions are supported: kebab-case (--primary-500), BEM-style (--color-primary--500), and Tailwind-style (--color-primary-500). Choose whichever matches your project's conventions. The generated output is a clean CSS :root {} block ready to paste into your stylesheet.

Dark mode support is built in. The tool can generate an inverted palette wrapped in either a @media (prefers-color-scheme: dark) query or a .dark class selector, depending on your framework's approach. The live preview panel shows how your theme looks applied to common UI elements — cards, buttons, inputs, and badges — so you can iterate quickly without leaving the page.

Five built-in presets (Default Dark, Default Light, Ocean Blue, Forest Green, Purple Dream) provide starting points you can customize. If you need precise color values, pair this tool with the Color Converter to translate between HEX, RGB, and HSL. For visual gradient tokens, try the CSS Gradient Generator. And if you are working with Tailwind CSS, the Tailwind CSS Converter can translate vanilla CSS to utility classes.

All processing runs entirely in your browser. No color data, theme configurations, or generated CSS is ever sent to a server. Your design tokens stay private on your machine.

How to Use

  1. Choose a Preset from the dropdown to start with a pre-configured theme, or begin from scratch by clicking Add Color.
  2. For each color, use the color picker or type a hex value to set the base color. Give it a descriptive name like primary, neutral, or brand.
  3. Review the auto-generated shade swatches (50–950) below each color to verify the scale looks correct.
  4. In the Semantic Tokens section, map color roles (background, text, primary, error, etc.) to a specific color name and shade.
  5. Select a Naming Convention (kebab-case, BEM, or Tailwind) that matches your project's style.
  6. Toggle Dark Mode on or off and choose the generation method (@media query or .dark class). Use the Live Preview toggle to switch between light and dark views.
  7. Click Copy or press Ctrl+Shift+C to copy the generated CSS :root {} block to your clipboard and paste it into your project's stylesheet.

Popular CSS Variable Examples

View all CSS variable examples →

FAQ

How are shade variations generated?

The tool converts each base color to HSL, then generates 11 shades (50 through 950) by varying the lightness value. Shade 50 is near-white (~97% lightness) and shade 950 is near-black (~10% lightness), with the base color typically closest to the 500 shade. The hue and saturation remain constant across all shades.

What naming conventions are supported?

Three conventions are available: kebab-case (--primary-500), BEM-style (--color-primary--500), and Tailwind-style (--color-primary-500). All three produce valid CSS custom properties. Choose the one that matches your project's existing convention or framework expectations.

How does dark mode generation work?

When dark mode is enabled, the tool inverts the lightness of each color in the HSL color space. For example, a light shade at 90% lightness becomes 10% lightness in the dark variant. You can choose between a @media (prefers-color-scheme: dark) query (which follows the user's OS setting) or a .dark class selector (for manual toggle implementations like next-themes).

What are semantic tokens?

Semantic tokens map abstract roles (like 'background', 'primary', 'error') to specific color values. Instead of using --blue-500 directly in your components, you reference --primary, which points to --blue-500. This lets you swap entire themes by changing only the semantic mappings without touching component styles.

Can I use this with Tailwind CSS?

Yes. Generate your CSS variables with the Tailwind naming convention, paste the :root block into your global CSS, then reference the variables in your tailwind.config.js theme.extend.colors section. For example: primary: 'var(--color-primary-500)'. This gives you custom colors available as Tailwind utilities like bg-primary.

Is my data safe?

Yes. All color calculations, shade generation, and CSS output happen entirely in your browser using JavaScript. No data is sent to any server. You can verify this by checking the Network tab in your browser's developer tools while using the tool.

How many colors can I add?

There is no hard limit. You can add as many base colors as needed. However, each color generates 11 shade variables, so a palette with 10 base colors produces 110 CSS variables (plus semantic tokens). For most projects, 3-6 base colors with semantic mappings provide a complete and manageable theme system.

Related Tools

Color Converter

Convert colors between HEX, RGB, HSL formats with contrast checker and palette generator.

CSS Gradient Generator

Create linear, radial, and conic CSS gradients visually with color stops, angle control, and live preview.

Box Shadow Generator

Design CSS box shadows visually with sliders for offset, blur, spread, and color. Multi-layer support.

Tailwind CSS Converter

Convert plain CSS to Tailwind CSS utility classes. Paste CSS rules and get equivalent Tailwind classes instantly.

CSS Layout Generator

Visually build Flexbox and CSS Grid layouts with live preview and generated CSS code.

Viewport Size Reference

Browse 60+ device viewport sizes for responsive web design. Compare iPhone, iPad, Android, laptop, desktop, and TV screen dimensions.

z-index Manager

Design and manage CSS z-index layer hierarchies visually. Generate CSS variables, Sass maps, or JS/TS objects with conflict detection.

SVG Path Editor

Visually edit SVG path d attributes with draggable control points, command palette, bezier curve handles, and real-time preview.

Color Palette Extractor

Extract dominant color palettes from images with HEX, RGB, HSL values. Export as CSS variables, Tailwind config, JSON, or SVG.

CSS Selector Reference

Complete interactive CSS selector reference with specificity calculator, live preview, searchable categories, and browser support for every selector.

Tailwind Config Builder

Build tailwind.config.js visually with custom colors, spacing, fonts, and breakpoints.

Design Tokens Generator

Generate design tokens as CSS custom properties, JSON, or SCSS variables.

Google Fonts Pair Finder

Find and preview complementary Google Fonts pairings for headings and body text.