Future of CSS: color-mix function 🎨
Andrew Bone

Andrew Bone @link2twenty

About: A British web developer, that is passionate about web accessibility.

Location:
Britain, Europe
Joined:
Jun 8, 2017

Future of CSS: color-mix function 🎨

Publish Date: Jul 16 '22
27 6

I always love to delve into the new and wonderful things coming to the web, today I'm going to look at the color-mix function which, at the time of writing, is not in any stable browser but has arrived in firefox behind a flag.

What does color-mix do?

The color-mix function allows you to mix colours (who'd have thought?) those colours can be named colours, hex colours or any sort of colour really. This is very exciting because it allows us to add some SCSS like functionality such as lighten, darken or even adjust-color's alpha.

Why are there colour spaces

Colour spaces are a whole other thing. A colour space is a way to mathematically define a set of colours. Using different colour spaces allows you to represent different colours. Naturally this means mixing colours in different colour spaces creates different results.

This is a video from Surma, while at Google, that explores colour spaces in more detail than I can.

Practical examples

I've thrown together a very quick example of some of the things you can do. As I mentioned earlier none of this code can run in a stable browser without flags so I've uploaded an image of the result too.

The examples I've done are,

  • tomato darkening by mixing with black,
  • teal lightening by mixing with white
  • purple becoming less opaque by mixing with transparent (technically a colour it seems)
  • red mixing to green

color-mix example

Fin

There we go, that's it for now. It's so cool to see little functions like this coming to css making it more powerful, maybe one day we won't need css pre processor's at all, especially with css nesting being talked about. Very exciting.

Thanks so much for reading. If you'd like to connect with me outside of Dev here are my twitter and linkedin come say hi 😊.

Comments 6 total

  • Calin Baenen
    Calin BaenenJul 16, 2022

    Þanks for introducing me to ðis!
    I can't wait until ðis feature is stable.

    • Andrew Bone
      Andrew BoneJul 16, 2022

      You're more than welcome, with interop going strong this year new features like this should arrive in all evergreen browsers faster than ever before!

      • Calin Baenen
        Calin BaenenJul 17, 2022

        in all evergreen browsers faster than ever before!

        Evergreen?

        • Andrew Bone
          Andrew BoneJul 17, 2022

          Browsers that are getting regular updates.

  • Andrew Bone
    Andrew BoneJul 16, 2022

    What new features are you looking forward to landing in stable?

  • Mohd Hassan Ashraf
    Mohd Hassan AshrafJun 5, 2025

    I recently learned react but I couldn't make sidebar would everyone help me to create one

Add comment