Tonal is a smart color palette generator inspired by Tailwind CSS — fully customizable, format-agnostic, and powered by OKLCH. Generate complete color scales in multiple formats (CSS, SCSS, JS, etc.) via CLI or programmatically.
npm install -g tonal-kitTonal expects a tonal.config.js file at the root of your project:
import { defineConfig } from 'tonal-kit';
export default defineConfig({
colors: {
red: '#ef4444',
blue: '#3b82f6',
neutral: '#737373',
// Add as many colors as you want
}
});Each color is defined using a single HEX value. Tonal will generate the full scale from 50 to 950.
Generate a palette file in the format of your choice:
tonal generateOptions:
| Flag | Description | Default |
|---|---|---|
--ext, -e |
Output file extension | css |
--format, -f |
Color model (hex, oklch, rgb, hsl) |
hex |
--file |
Output filename (without extension) | colors |
--out-dir, -o |
Output directory | ./tonal |
--preview, -p |
Also generate and open a visual preview | tonal/preview.html |
Example:
tonal generate -e scss -f oklch --previewGenerates ./tonal/colors.scss and opens the preview in browser.
Only generate a preview HTML file to visualize the palette:
tonal previewOptions:
| Flag | Description | Default |
|---|---|---|
--format, -f |
Color model to preview | oklch |
--file |
Output HTML file | tonal-preview.html |
--open, -o |
Open the preview in browser | false |
Use Tonal in a frontend or Node.js context:
import { generatePalette, exportPalette } from 'tonal-kit';
const palette = generatePalette('blue', '#3b82f6', 'oklch');
const css = exportPalette({ blue: palette }, 'css');
console.log(css); // → Full :root CSS blockUseful for live previews or copy-paste snippets.
:root {
--blue-50: #eff6ff;
--blue-100: #dbeafe;
--blue-500: #3b82f6;
--blue-950: #0c1b34;
}$blue-50: #eff6ff;
$blue-500: #3b82f6;@blue-50: #eff6ff;
@blue-500: #3b82f6;blue-50 = #eff6ff
blue-500 = #3b82f6export const blue = {
50: '#eff6ff',
100: '#dbeafe',
500: '#3b82f6',
950: '#0c1b34'
};Tonal uses perceptual OKLCH space and curve-based rules to:
- Create color scales from a single value
- Handle neutral tones gracefully
- Automatically shift hue/chroma across the tonal range
Contributions are welcome! Please open an issue or submit a pull request.
npm installnpm testAll new features must include unit tests. The current test suite covers:
- Generates exactly 11 stops (50 → 950)
- Handles low contrast and dark input colors
- Throws an error on invalid input (e.g.,
'r') - Returns correct output formats (hex, oklch, rgb, hsl)
- Matches expected syntax per format using regex
- Generates one and only one
:root {}block in CSS - Ensures no duplicate variable names
- Ensures color names and values are present
- Correct color format is used in style blocks
- Verifies output file is correctly written
- Simulates options like
--out-dir,--file,--preview - Ensures
--filenaming is respected - Optionally mocks
open()to ensure it is triggered when expected
Feel free to add more formats or improve existing ones. If you have a specific format in mind, let us know! We can add it to the list of supported formats.
MIT