If you inspect a modern webpage built with Tailwind CSS v4, shadcn/ui, or Linear using window.getComputedStyle(), classic CSS pickers break in surprisingly ugly ways:
- CSS Color 4 everywhere: Chromium now returns
oklch(),oklab(), andcolor(display-p3 ...)instead ofrgb(). Any regex looking forrgba?()silently drops colors and breaks WCAG contrast checks. - Computed-style bloat: Dumping raw computed styles spits out dozens of browser defaults (
position: static,opacity: 1, flex properties on block containers, and 4 separatepadding-*/border-*declarations). - Sub-pixel grid tracks:
getComputedStyle(el).gridTemplateColumnsresolvesrepeat(3, minmax(0, 1fr))into something like312.33px 312.34px 312.33px. Naive string equality missesgrid-cols-3by0.01px. - Translucent dark glass cards: Checking contrast against a card with
background-color: rgba(255, 255, 255, 0.08)without alpha-compositing up the ancestor stack thinks the card is on pure white.
Here is how I solved these four problems in zero-dependency vanilla JS — plus two free client-side tools you can test right in your browser.
1. Parsing oklch(), oklab(), and display-p3 + Palette Snapping
Tailwind CSS v4 defines its palette in OKLCH. When you convert OKLCH back to 8-bit sRGB using Bjorn Ottosson's inverse OKLab matrix, rounding can shift a channel by ±1 (for example, #18181b might round to #18181c).
To avoid emitting ugly arbitrary hex classes (bg-[#18181c]), we:
- Decode
oklch(),oklab(),hsl(),color(srgb ...), andcolor(display-p3 ...)into{ r, g, b, a }. - Match the opaque RGB against all 21 standard Tailwind v4 color palettes (
slate,gray,zinc,neutral,indigo,violet,rose, etc.) with a tight Euclidean RGB snap tolerance (<= 4). - Emit clean Tailwind v4 alpha modifiers when
a < 1(e.g.text-white/80,border-white/10).
function matchTailwindPaletteToken(rgba) { const opaqueHex = rgbaToHex({ r: rgba.r, g: rgba.g, b: rgba.b, a: 1 }); if (EXACT_COLORS.has(opaqueHex)) return EXACT_COLORS.get(opaqueHex); let best = null; let bestDist = 17; // Euclidean distance <= 4 for (const entry of PALETTE_RGB_ENTRIES) { const dr = rgba.r - entry.r; const dg = rgba.g - entry.g; const db = rgba.b - entry.b; const d2 = dr * dr + dg * dg + db * db; if (d2 < bestDist) { bestDist = d2; best = entry.token; } } return best; } 2. Sub-Pixel Grid Track Tolerance & Zero-Bloat Style Diffing
Instead of blindly dumping every computed property, we diff each node against a clean same-tag baseline inside a hidden sandboxed iframe, drop flex/grid-only properties when display isn't flex/grid, collapse 4-side shorthands (padding, margin, border-radius), and treat grid tracks within 2px of each other as equal columns:
const cols = declarations['grid-template-columns'].trim().split(/\s+/); const pxCols = cols.map(parsePx); const allEqualTracks = cols.length >= 2 && cols.length <= 12 && ( cols.every((c) => c === cols[0]) || (pxCols.every((n) => n !== null && n > 0) && Math.max(...pxCols) - Math.min(...pxCols) <= 2) ); if (allEqualTracks) classes.push(`grid-cols-${cols.length}`); We also compile modern visual rules that older converters drop:
-
backdrop-filter: blur(12px)->backdrop-blur-md -
linear-gradient(...)/radial-gradient(...)->bg-[linear-gradient(...)] -
background-clip: text->bg-clip-text -
text-overflow: ellipsis+overflow: hidden+white-space: nowrap->truncate - Explicit computed
width,height, andxmlnson stripped inline<svg>icons so they don't blow up to 100% viewport width when pasted into React JSX.
3. Real Input -> Compiled Tailwind CSS v4 Output
Feed this modern Linear-style dark glass card into the compiler:
.card { display: grid; grid-template-columns: 312.33px 312.34px 312.33px; gap: 24px; background-color: oklch(0.21 0.006 285.885); color: rgba(255, 255, 255, 0.8); border: 1px solid rgba(255, 255, 255, 0.1); backdrop-filter: blur(12px); background-image: linear-gradient(135deg, #2563eb, #7c3aed); } Output:
grid gap-6 grid-cols-3 bg-zinc-900 bg-[linear-gradient(135deg,#2563eb,#7c3aed)] text-white/80 border border-white/10 backdrop-blur-md Try the Free Local Tools (Zero Ads, Zero Sign-Up)
Both web tools run 100% client-side in vanilla JS (full client-side source is public on GitHub at orziz/orzi-apps-site):
- CSS to Tailwind CSS v4 & React JSX Converter — Paste any CSS block, strip browser defaults, and preview live output.
- OKLCH Color Converter, WCAG 2.1 Contrast Checker & Tailwind v4
@themeBuilder — Audit AA/AAA contrast ratios and export Tailwind v4@theme,:rootCSS variables, or W3C DTCG JSON.
Companion Side-Panel Extension: SpecQuill
I also packaged the exact same local engine into a lightweight browser side-panel extension called SpecQuill so you can inspect live webpages without copy-pasting from DevTools:
- Hover any element for box dimensions,
Alt-key pixel spacing redlines, arrow-key DOM navigation, and multi-layer composited WCAG AA/AAA contrast badges. - Export clean HTML/CSS, React JSX + Tailwind v4, full-page OKLCH palettes, inline SVGs, or token-budgeted AI coding specs for Cursor / Claude Code.
- 100% local processing with least-privilege permissions (no
<all_urls>background access). - Install Free on Microsoft Edge Add-ons (Chrome Web Store review is currently in progress; v1.1.0 ZIP for Chrome/Brave is available on apps.orzi.me/specquill). Core inspection, clean HTML/CSS, CSS variables, and 3 daily Pro exports are free forever, with an optional
$12one-time lifetime Pro upgrade (no subscription).
If you run into tricky real-world CSS edge cases (weird shorthand orders, color-mix(), complex grid-template-areas, or nested gradients), drop them in the comments and I'll add test coverage to the compiler!


