twpalette
v1.0.1
Published
CLI that generates a complete Tailwind v4 color palette (50–950) from any single color input.
Maintainers
Readme
twpalette
A CLI tool that generates a complete Tailwind CSS color palette from any single color input.
Give it a color in any format — hex, OKLCH, HSL, RGB — and it outputs a full 50–950 palette as CSS custom properties, matched to the closest Tailwind v4 color family and scaled to your input color's hue and chroma.
Usage
npx twpalette <color>Examples:
npx twpalette "#3b82f6"
npx twpalette "oklch(0.637 0.237 25.33)"
npx twpalette "hsl(220 90% 56%)"
npx twpalette "rgb(59 130 246)"The output shows a colored swatch grid followed by CSS custom properties ready to paste into your stylesheet. The /* main shade */ comment marks the shade that maps closest to your input color's lightness.
How it works
- Family matching — finds the closest Tailwind color family using deltaE color distance in OKLCH space
- Shade matching — identifies which shade (50–950) best matches your input color's lightness
- Palette scaling — applies your input color's hue offset and chroma ratio to the entire family template
- Naming — looks up the nearest named color from a curated list
Install
npm install -g twpaletteOr run directly without installing:
npx twpalette <color>Requirements
- Node.js >= 22
Development
Source lives in src/ as TypeScript and runs directly on Node.js >= 23.6 via native type stripping — no build step needed for local use:
./src/cli.ts "#3b82f6"The npm tarball ships pre-compiled JavaScript from dist/, so installed consumers don't need a TypeScript-capable Node. To publish:
npm run build
npm publishCredits
- chroma-js — does the heavy lifting: color parsing across every input format, OKLCH conversions, and deltaE distance calculations. BSD-licensed.
- Tailwind color families — the base OKLCH values for each shade (50–950) in src/families.json are derived from the Tailwind CSS v4 default palette: tailwindlabs/tailwindcss · packages/tailwindcss/src/compat/colors.ts. Tailwind CSS is MIT-licensed.
- Color names — the named-color lookup in src/names.json is filtered down from the "short" list published by meodai/color-names at unpkg.com/color-name-list/dist/colornames.short.json (kept only single-word names, deduplicated).
color-namesis MIT-licensed.
License
MIT — see LICENSE.
