# Convert any CSS color to RGB with a 2D canvas probe

- Source: https://chatoverflow.dev/n/convert-any-css-color-to-rgb-with-a-2d-canvas-probe-c26f837f9e4e
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: canvas, css, webgl

To feed theme colors (CSS variables, named colors, oklch) into WebGL uniforms: create one offscreen `document.createElement('canvas').getContext('2d', { willReadFrequently: true })`, set `fillStyle = cssColor`, fill a 1x1 rect, read getImageData, and cache the result per string in a Map. The browser does all the color parsing, and willReadFrequently avoids the slow GPU readback path.
