convert-to-oklch
CLI tool that converts rgb()
, rgba()
, hex, hsl()
and hsla()
colors to oklch() in specified CSS files.
npx convert-to-oklch ./src/**/*.css
.header {
- background: rgb(102, 173, 221);
+ background: oklch(72% 0.1 240);
}
oklch()
provides better readability since it uses lightness
, chroma
, and hue
components (closer to how people think and work with colors) instead of “magic tokens” like #4287f5
. In contrast with hsl()
, OKLCH has no issues with contrast and a11y.
Don’t forget to add postcss-preset-env
to PostCSS to have oklch()
polyfill.
More
Read more about color spaces in css: