Menu

Fix html2canvas 'Attempting to parse an unsupported color function "oklch"' (Tailwind CSS v4)
📰

Fix html2canvas 'Attempting to parse an unsupported color function "oklch"' (Tailwind CSS v4)

DEV Community: css·Cyber Pusa·about 3 hours ago
#T2noipek
#devtocss#devto#dev#capture#html2canvas
Reading 0:00
15s threshold

When you call html2canvas() on a page that uses Tailwind CSS v4 — or any stylesheet that emits modern CSS color functions — the official html2canvas package may throw:

Attempting to parse an unsupported color function "oklch"

Enter fullscreen mode

Exit fullscreen mode

The same parser also rejects related functions, so you may instead see "oklab" , "lab" , "lch" , "color" , or "color-mix" in the message.

Why it happens

html2canvas does not take a real screenshot. It walks the DOM, reads computed styles, and paints a canvas itself. That means it has to parse CSS color values.

Tailwind CSS v4 uses the oklch() color space for its default palette. The browser is fine with that. Official html2canvas 1.4.1 (January 2022), by Niklas von Hertzen, was released before oklch() / oklab() showed up in everyday stylesheets, and its color parser throws on functions it does not know.

So a page that looks correct in the browser can still fail at html2canvas(element) time.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.