What Does the CSS Variable Formatter Do?
Design systems, brand guidelines and Figma files are full of colours, but turning them into clean code by hand is tedious and error-prone. This CSS variable formatter takes a messy list of colours, in any format, with or without names, and converts it into perfectly formatted CSS custom properties (--primary: #2563EB;) or the variable syntax of your framework of choice. It understands HEX, RGB, HSL and CSS colour names, strips existing --, $ and @ prefixes and colons, and names unnamed colours automatically.
It's ideal for setting up a theme file, migrating from SCSS to CSS variables or to Tailwind, documenting a palette, or quickly turning the output of a palette generator into code you can paste into a project.
How to Use It
- Paste your colours, one per line. Names are optional: "Primary: #2563EB", "accent = rgb(245,158,11)", "$danger: #DC2626;" and a bare "#0F172A" all work.
- Choose the output: CSS custom properties, SCSS, LESS, Tailwind v3 config, Tailwind v4
@theme, JSON or TypeScript. - Choose the value format: HEX, rgb(), hsl() or bare channels for alpha support.
- Set the naming: kebab-case, camelCase or snake_case, with an optional prefix such as
colororbrand. - Copy or download the result. The preview shows every colour with its variable name.
Why Use CSS Custom Properties for Colours?
CSS custom properties (often called CSS variables) let you define a colour once and reuse it everywhere with var(--primary). Change it in one place and the whole site updates. Unlike SCSS variables, they work at runtime in the browser, so you can:
- Build light and dark themes by redefining the same variables inside
@media (prefers-color-scheme: dark)or a[data-theme="dark"]selector. - Theme components by overriding variables on a parent element.
- Change colours with JavaScript using
element.style.setProperty('--primary', '#e11d48'). - Share tokens between CSS, inline SVG and web components.
RGB Channels: Variables with Transparency
A common problem: if --primary is #2563EB, you can't easily make it 10% transparent. The solution is to store bare channels, --primary: 37 99 235;, and then use rgb(var(--primary) / 0.1) for any opacity you like. Tailwind uses the same pattern, with rgb(var(--primary) / <alpha-value>), so utilities like bg-primary/20 work. Choose "RGB channels" or "HSL channels" in the value format to generate this style. In modern browsers you can also use color-mix(in srgb, var(--primary) 10%, transparent) with ordinary HEX values.
Output Formats Compared
| Format | Example | Use with |
|---|---|---|
| CSS custom properties | --primary: #2563EB; | Any website, all modern browsers |
| SCSS | $primary: #2563EB; | Sass projects, Bootstrap themes |
| LESS | @primary: #2563EB; | LESS projects, older Ant Design |
| Tailwind v3 config | 'primary': '#2563EB' | tailwind.config.js theme.extend.colors |
| Tailwind v4 @theme | --color-primary: #2563EB; | Tailwind CSS 4 CSS-first config |
| JSON / TypeScript | "primary": "#2563EB" | Design tokens, React Native, charts, JS apps |
Naming Tips for Colour Variables
- Name by purpose, not appearance:
--color-dangersurvives a rebrand, while--reddoesn't. - Use a two-layer system: raw palette tokens (
--blue-600) plus semantic tokens (--color-primary: var(--blue-600)). - Be consistent with case and prefixes across your codebase. kebab-case is standard in CSS.
- Include states like
--primary-hoverand--primary-subtlefor interactive elements.
Features
- Accepts anythingHEX, RGB, HSL and names, from CSS or SCSS lines.
- Seven outputsCSS, SCSS, LESS, Tailwind v3/v4, JSON and TS.
- Channel valuesFor opacity-ready variables.
- Smart namingNearest colour names for unnamed values.
- Duplicate-safeRepeated names get unique suffixes.
- Copy and downloadWith the right file extension.
Light and Dark Themes with CSS Variables
Once your colours are variables, supporting dark mode takes only a few lines. Define the light values on :root, then redefine the same names inside @media (prefers-color-scheme: dark) { :root { ... } } or a [data-theme="dark"] selector. Components that use var(--surface) and var(--text) switch automatically, with no extra classes. Generate your light palette here, then run the dark palette through the tool with the same names to get a matching block.
Frequently Asked Questions
Do CSS variables work in all browsers?
Yes, in every modern browser. Only Internet Explorer lacks support.
What's the difference between CSS and SCSS variables?
SCSS variables are replaced at build time. CSS variables live in the browser and can change at runtime, for example for dark mode.
Where do I put :root variables?
At the top of your main stylesheet, so they're available to every element.
Can I paste a whole CSS file?
Yes. Any line containing a colour is converted, and lines without one are skipped and reported.
How do I add transparency to a CSS variable colour?
Store channels (37 99 235) and use rgb(var(--x) / 0.5), or use color-mix().