Skip to main content

Why CSS `color-mix()` is kinda useless

I am a HUGE fan of CSS. I don't always make my sites look pretty (just look at my latest creation at wordle.barrybenson.dev), but the thing is CSS is fan-freaking-tastic. I have my issues with Tailwind, but even that can do the vast majority of what CSS can do, and I love it. New CSS features like "if()" and custom properties are game changers. What isn't a game changer, to me, is the new "color-mix()" function.

From a purely functional standpoint, the color-mix() function is actually pretty dope. If you want to use it, I have a good video from Kevin Powell for you to watch below this paragraph.


Even having watched this video, however, I don't get it. I just don't. From a functional standpoint, it can do a lot of good things, but from a design to implementation standpoint... it is the most useless CSS feature we've had come out in the last five years.

Introducing a book titled Refactoring UI, by Adam Wathan and Steve Schoger of TailwindCSS fame. In the book there is an entire chapter titled "Working with Color" that gives solid (though slightly outdated in my copy) advice for color. In this chapter, there is a subchapter about defining your shades up front, meaning you should select five to ten colors for primaries, neutrals, and a few accent colors each with their own shades. These shades should be defined by the designer (or developer if no designer is on the team) with intention.

Here is a snippet from the book that really illustrates why color-mix() is practically useless. "As tempting as it is, you can’t rely purely on math to craft the perfect color palette. A systematic approach like the one described above is great to get you started, but don’t be afraid to make little tweaks if you need to. Once you actually start using your colors in your designs, it’s almost inevitable that you’ll want to tweak the saturation on a shade, or make a couple of shades lighter or darker. Trust your eyes, not the numbers. Just try to avoid adding new shades too often if you can avoid it. If you’re not diligent about limiting your palette, you might as well have no color system at all."

There is one part in there where color-mix() may possibly be useful, except for one tiny little problem we will discuss in a moment. "...it’s almost inevitable that you’ll want to tweak the saturation on a shade, or make a couple of shades lighter or darker." This sounds like a perfect situation for color-mix(), right?

Eh, not so much. See, CSS now has this feature where you can take a color (from any space), and use it in another, and change it, all at the same time. This is called "relative color", because it creates a new color relative to the color you give it. It looks something like this:


This is an OKLCH color, relative to the hex code for fuchsia, just with a change of hue. This isn't far off from how you would actually use this feature in practice, either.

That is, however, if you're not defining an entire color palette up front, completely intentionally. Even this feature is only partially useful, however, it can do infinitely more than color-mix() because it's supported in every color function, including RGB, HSL, etc..

I genuinely cannot think of a good reason to use color-mix(), except to mix colors to make a color you can envision, but somehow not implement in HSL or OKLCH. There isn't a lot of use cases I have seen that show color-mix() to be worth while in any modern CSS project.

Comments

Popular posts from this blog

TailwindCSS is a Not The Best

No doubt is Tailwind a useful tool, especially for prototyping, but ultimately I feel as if it promotes terrible developer practices with flimsy, half-baked, ideologies powering its design. Ultimately I am not here to tell you that you're wrong for using TailwindCSS, use whatever tools make your life easier. But I care a lot about the tiny optimizations one can make to build better styles for the web, and here are my findings. NOTE: This is more of a ramble than anything else. Adam Wathan's (in)Famous Blog Article Adam Wathan wrote an article (that I just need to rant about for just a moment) titled  CSS Utility Classes and "Separation of Concerns" , and before even clicking the article itself,  on the list of articles , Adam describes the article as  Why “separation of concerns” is the wrong way to think about CSS and why presentational classes scale better than semantic classes.  I strongly disagree that separation of concerns is the wrong way to think about CSS. C...

5 Stupid Ideas I've Had This Month

This month has been great for my stupid ideas to flow. Highdeas as I call them because I am usually (like right now) high while I come up with them. These ideas are too stupid, or I myself am too stupid, to work on them, so I thought I'd share these ideas with the world. 1: Yet Another Generic/User-Friendly Arch Distro (YAGAD/YAUFAD) The TL;DR of this project is just to build another Arch-based distribution just to see how far I can take it. With the failure of my management of Illumarine, a much more complex project, I thought maybe I could do something like this and get something done. Basically it's a generic Arch install with a bunch of default apps, a simple and easy GUI like KDE and/or GNOME, and some generic installation tool. 2: A crappy Linux installer written in Electron A simple plug-and play, easy to modify and stylize system installer for Linux written in Electron, or Tauri, whichever suits your boat. 3: An Electron alternative based on Bun and modern WebKit The id...