Skip to content

Instantly share code, notes, and snippets.

@svgeesus
Last active October 14, 2021 16:29
Show Gist options
  • Save svgeesus/7298c61254db05ec190c21f76ded6c7b to your computer and use it in GitHub Desktop.
Save svgeesus/7298c61254db05ec190c21f76ded6c7b to your computer and use it in GitHub Desktop.

CSS Color 5 simple mix

Effect of mixing colorspace

50% white, 50% sRGB blue, in LCH, OKLCH

For https://drafts.csswg.org/css-color-5/#color-mix

let color = new Color("white");
color.to("lch").toString({precision:6});
color.to("oklch").toString({precision:6});
let color2 = new Color("blue");
color2.to("lch").toString({precision:6});
color2.to("oklch").toString({precision:6});
let mix_lch= color.range(color2, {
    space: "lch", // interpolation space
    outputSpace: "srgb"
});
let mix_ok= color.range(color2, {
    space: "oklch", // interpolation space
    outputSpace: "srgb"
});
let mix_srgb= color.range(color2, {
    space: "srgb", // interpolation space
    outputSpace: "srgb"
});
let blend_lch = mix_lch(.5);
blend_lch.to("lch").toString({precision:6});
blend_lch.to("oklch").toString({precision:6});
let blend_ok = mix_ok(.5);
blend_ok.to("oklch").toString({precision:6});
let blend_srgb = mix_srgb(.5);
blend_srgb.to("oklch").toString({precision:6});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment