DevTools Logo

Tailwind Theme to CSS Variables

Tailwind Theme to CSS Variables

Transpile a Tailwind v3 theme into CSS custom properties

Runs in your browser
Try an example

Tailwind config

12 lines · 289 chars

CSS variables

11 variables
:root {
  --color-primary: #2563eb;
  --color-primary-500: #2563eb;
  --color-primary-500-rgb: 37 99 235;
  --color-primary-700: #1d4ed8;
  --color-primary-700-rgb: 29 78 216;
  --color-primary-rgb: 37 99 235;
  --color-surface: #ffffff;
  --color-surface-rgb: 255 255 255;
  --font-family-sans: Inter, "Segoe UI", sans-serif;
  --spacing-4: 1rem;
  --spacing-8: 2rem;
}

Examples

Nested palette plus spacing and fonts

Input
{ theme: { extend: { spacing: { 4: '1rem' }, color: { primary: { 500: '#336699' } }, fontFamily: { sans: ['Inter', 'sans-serif'] } } } }
Output
--color-primary-500: #336699; --spacing-4: 1rem; --font-family-sans: Inter, sans-serif;

Each section walks to its kind prefix with kebab-case paths; arrays join font stacks with commas.

Alpha-ready brand color

Input
{ colors: { brand: '#0f172a/<alpha-value>' } }
Output
--color-brand-rgb: 15 23 42; --color-brand: rgb(var(--color-brand-rgb) / <alpha-value>);

The hex converts to an RGB triplet and the variable rewrites through var() so opacity modifiers apply.

About this tool

Tailwind to CSS Variables transpiles a theme config with transpileTailwindConfig(input): a comment-stripping LiteralParser (/* */ and // removed first) accepts object literals, module.exports assignment, quoted and bare keys, strings, numbers, booleans, and arrays — then walks the colors/color (kind color), fontFamily (kind font-family), and spacing sections, whether nested under theme.extend or at the root. Empty input returns a Paste-a-Tailwind error; unparseable text returns error with empty css.

Walking is deterministic: object keys sort alphabetically, nested color trees flatten to kebab-case paths (--color-primary-light-default), fontFamily arrays join with , (--font-family-sans: Inter, sans-serif), and spacing scalars emit --spacing-* — every variable sorts by name into a :root block. Nullish values warn as skipped, and function-valued entries (function keyword or => arrows) are never evaluated: the sentinel path records Skipped function value at colors.dynamic. and the variable is omitted.

Opacity-ready colors get first-class treatment: any color whose value contains <alpha-value> also emits a --color-<path>-rgb triplet derived from the hex (e.g. #0f172a → 15 23 42), and the main variable rewrites to rgb(var(--color-<path>-rgb) / <alpha-value>). Non-hex colors pass through verbatim with no rgb helper.

How to use this tool

  1. Paste the theme object

    Supply the config literal (comments allowed) with colors/color, fontFamily, or spacing — under theme.extend or at the root — and read css plus sorted variables.

  2. Flatten nested palettes

    Nest shades freely (primary: { 500, light: { DEFAULT } }); each leaf becomes --color-<kebab-path> in sorted order.

  3. Keep opacity modifiers working

    Write hex colors as #0f172a/<alpha-value> to get the -rgb triplet plus the rgb(var(...-rgb) / <alpha-value>) rewrite.

  4. Heed the warnings

    Function values are skipped with a Skipped function value warning — replace dynamic entries with literals before emitting.

Use cases

Bridging Tailwind tokens to vanilla CSS

Export --color-*, --spacing-*, and --font-family-* variables for non-Tailwind stylesheets or component libraries.

Auditing dynamic theme values

Find function-valued entries via warnings and replace them with static literals the transpiler can emit.

Shipping opacity-compatible palettes

Generate -rgb triplets alongside <alpha-value> colors so bg-brand/50 style modifiers resolve at runtime.

Common mistakes

Mistake:Putting executable functions in the pasted config.

Fix:Arrow functions and function keywords are never evaluated — they warn and skip. Paste plain literals only.

Mistake:Expecting every section of the config to be emitted.

Fix:Only colors/color, fontFamily, and spacing walk; other keys are ignored, and empty results still render :root {}.

Mistake:Writing <alpha-value> on a non-hex color.

Fix:The -rgb helper derives from #rrggbb hex only; named or rgb() colors pass through with no triplet.

Frequently asked questions

What does this tool do?

It transpiles a Tailwind theme literal with transpileTailwindConfig into sorted :root CSS variables: colors/color → --color-*, fontFamily → --font-family-*, spacing → --spacing-*, from theme.extend or the root object, with comment stripping and literal-only parsing.

How do nested colors, fonts, spacing, alpha helpers, and comments behave?

primary: { 500, light: { DEFAULT } } flattens to --color-primary-*-* kebab paths; sans: ['Inter','sans-serif'] joins with commas; spacing scalars emit --spacing-*; #0f172a/<alpha-value> adds --color-brand-rgb: 15 23 42 plus an rgb(var()) rewrite; and // plus /* */ comments are stripped before parsing.

Is my config uploaded or stored?

No. Comment stripping, literal parsing, tree walking, and CSS emission run entirely in your browser — configs never leave your device.

Why is a value missing from the output?

Function values (=> or function) are never evaluated — they warn Skipped function value at colors.dynamic. and are omitted. Replace them with literals; malformed input instead returns error with empty css.

References & standards