← HomeAll tools · 中文
Late-night workbench · 12 token roles

Code Color Lab: mix a syntax theme that is yours

Tune one role at a time on the left while real code re-renders live on the right; weak contrast is flagged on the spot, and the finished theme exports as VS Code JSON plus CSS variables.

Tweaks today: 0 · favorite themes: 0

Pick a base theme 9 original HSL variants · gold tag = today's pick

Role swatches number at right = contrast against background

Live code preview colored by a hand-written tokenizer, not an image

Export & favorites files are generated in your browser

Your palette, favorites and preview code live only in this device's browser - no upload, no sign-in. Clearing the cache or switching devices loses them. To erase everything, use "Clear my data" in the footer.

Ten minutes to start: pick a base, then move three colors

Don't start from a pure white background. Click the built-in theme closest to your taste, then touch only the three roles with the biggest impact: foreground text decides how tiring the page feels, keyword sets the visual center of gravity, string controls color density. Settle those three and the whole theme has its personality.

Change any color and the real JavaScript in the right-hand preview redraws instantly - the preview runs a lightweight tokenizer written into this page that walks keywords, strings, comments, numbers and function names, so what you see is the final rendering, not a mock-up.

Not sure where to start? Hit "Nudge": the background stays put while every other hue drifts a little at random, and it often lands on something more harmonious than manual tuning.

Why anything below 4.5:1 is flagged

Most "moody" themes fail the same way: comments melt into the background, strings turn gray on dark ground. WCAG sets the AA bar for normal text at 4.5:1. This tool compares every token color against your background one by one, flags swatches in red below the threshold, and summarizes the offenders.

Comments may sit lower than body text, but not under 3:1 - anything less might as well delete them. Two patterns are truly fatal: a desaturated gray foreground on a light theme, and blue keywords on a dark-blue background. Both scream in the preview yet hide on the swatch list, which is why the numbers beat the eye.

Who the two exports are for

VS Code theme JSON: contains colors (editor background, foreground, line numbers) and tokenColors (your roles mapped to TextMate scopes). Drop it into a minimal theme extension's package.json and install it in VS Code; Sublime and other TextMate-based editors read the same scopes.

CSS variables file: paste variables like --code-keyword into your blog or docs stylesheet, hang a class per role on code blocks, and the same palette carries over. Both files regenerate from the current palette on every click - tune, then export again.

Roles12: background, foreground, keyword, string, comment, number, function, type, operator, punctuation, variable, constant
Themes9 original HSL-generated variants; a "today's pick" rotates by date on every visit
ContrastAll 11 roles scored against the background with WCAG ratios; below 4.5:1 is flagged
ExportVS Code theme JSON + CSS variables table, built as local Blobs - no network requests
PreviewA ~60-line tokenizer written into the page: comments, template strings, radix numbers; on parse failure it degrades to monochrome
LimitsLexing targets C-like syntax - PHP/SQL-specific keywords are not fully covered; favorites and palettes never sync across devices

FAQ

What is a token role?
The category an editor assigns to each span of code: background, foreground text, keyword, string, comment, number, function name, type, operator, punctuation, variable and constant - twelve roles in all. Each role gets one color, and syntax highlighting is exactly that: coloring by role.
What do the contrast warnings mean?
The tool computes the WCAG contrast ratio between every token color and your chosen background. Normal text needs at least 4.5:1 (AA level). Anything below the threshold is flagged in red, so you never ship a theme that looks great but is hard to read.
How do I use the exported files?
VS Code theme JSON: drop it into the colors/tokenColors of a minimal theme extension under ~/.vscode/extensions, or reference it from your own extension. CSS variables file: paste it into your blog or docs stylesheet and color code blocks with var(--code-keyword) and friends.
Are my palette or code uploaded anywhere?
No. Tokenizing, contrast math and file export all run inside your browser and the page sends no requests. Your palette, favorites and preview code live only in this device's localStorage, and the footer has a clear-data button.