CSS color-mix() for Hover, Active, and Disabled Button Colors
Set the button's base color once in --brand, then build the hover color by mixing in 15% black and the disabled color by mixing in 60% white, both with color-mix(). You don't need a separate color value for each state. Changing --brand alone updates the colors of all the states together.
The test environment was Ubuntu 24.04, Node.js 22.23.4, Playwright 1.63.0, and Chromium 153. I opened the button in Playwright, put it into the actual hover and pressed states, and read the getComputedStyle values and the on-screen pixel colors. I did not test the display in Firefox or Safari. The browser versions listed below come from the compatibility data (@mdn/browser-compat-data 8.1.8).
- 1. Mix black or white into the base color to make each state's color
- 2. Change only –brand when switching colors
- 3. Use oklch as the mixing color space
- 4. For disabled colors, mix in white or mix in transparent
- 5. Write :hover before :disabled, or add :not(:disabled)
- 6. When the percentages don't add up to 100%
- 7. Supported browsers
Mix black or white into the base color to make each state's color
This is the CSS I used for the test. The button background is set with --bg, and each state changes only --bg.
:root {
--brand: #1a73d6;
}
button {
--bg: var(--brand);
background: var(--bg);
color: #fff;
border: 0;
border-radius: 8px;
padding: 10px 20px;
cursor: pointer;
}
button:hover {
--bg: color-mix(in oklch, var(--brand), black 15%);
}
button:active {
--bg: color-mix(in oklch, var(--brand), black 30%);
}
button:disabled {
--bg: color-mix(in oklch, var(--brand) 40%, white);
cursor: not-allowed;
}
.danger {
--brand: #d83a52;
}
color-mix(in oklch, var(--brand), black 15%) mixes 85% of --brand with 15% black in the oklch color space. If you omit one percentage, the other one is 100% minus the value you wrote. In the disabled rule, var(--brand) 40%, white gives white 60%. The rules for the percentages are summarized on MDN's color-mix() page.
When I put the button into each state in the test environment, the results looked like this:

In the normal state, the computed background color was rgb(26, 115, 214). On hover, it was oklch(0.476654 0.145889 255.232). When I read a color-mix() result with getComputedStyle, it came back not as rgb() but in the notation of the color space used for the mix (here, oklch()).
Change only –brand when switching colors
In the CSS above, setting --brand to red inside .danger was enough to give the red button its hover and disabled colors. The computed hover value was oklch(0.502598 0.164443 17.1849), which is red mixed with black.
This works because the color-mix() for --bg is written inside the button rule. If you instead compute the hover color at :root, as below, the hover color stays blue inside .danger.
:root {
--brand: #1a73d6;
--brand-hover: color-mix(in oklch, var(--brand), black 15%);
}
.danger {
--brand: #d83a52;
}
.box {
background: var(--brand-hover);
}
In the test environment, I checked .box inside .danger. --brand was #d83a52, but --brand-hover was still color-mix(in oklch, #1a73d6, black 15%), and the background was the blue hover color. In the CSS custom properties specification, the computed value of a custom property is the value after its var() references are substituted, and that value is inherited by child elements. At :root, var(--brand) was already replaced with the blue, so the result passes down to the children unchanged. Changing --brand in a child does not affect it.
If you write color-mix() in the rule for the element that uses the color (here, button), it is calculated using the --brand that applies to that element.
Use oklch as the mixing color space
The color space you write after in changes the result, even at the same 15%. In the test environment, I mixed black at 15% into two base colors and compared the contrast ratio against white text.
| Base color | Original color | in srgb, black 15% | in oklch, black 15% |
|---|---|---|---|
| #1a73d6 | 4.70 | #1662b6 (6.08) | #135bac (6.73) |
| #d83a52 | 4.52 | #b83146 (5.89) | #ae2d40 (6.46) |
With the same percentage, the oklch mix was darker, and its contrast ratio against white text was higher.
When I mixed in white, the difference in hue between srgb and oklch was clear. Mixing 60% white into red (#d83a52) gave a bluish pink in srgb, and a pale color close to the original red in oklch. Measured by the oklch hue value, the original color is 17.18. The oklch mix also stays at 17.18, but the srgb mix shifts to 8.76. For yellow (#e0a800), the srgb hue moved from 84.42 to 91.75, toward green.

MDN explains that oklch is a good choice when you want to avoid the grayish results that mixing can produce, and that srgb can sometimes become too dark or grayish. For button state colors, where you want to keep the original hue and change only the lightness, mixing in oklch usually gives the result you expect.
You can also write color-mix(var(--brand), black 15%) without in. The CSS Color 5 specification says that when in is omitted, the mix is done in oklab. In the test environment, this gave the same color as in oklab. The compatibility data does not list the omitted-in form as a separate entry, so I can't tell which versions support it. I write in explicitly so the code makes clear which color space is used.
For disabled colors, mix in white or mix in transparent
Instead of mixing in white, you can mix in transparent to make a semi-transparent disabled color. The examples below use srgb.
/* Mix in white */
button:disabled {
--bg: color-mix(in srgb, var(--brand) 40%, white);
}
/* Mix in transparent */
button:disabled {
--bg: color-mix(in srgb, var(--brand) 40%, transparent);
}
On a white background, both versions rendered as rgb(163, 199, 239), and they looked the same. Setting opacity: 0.4 produced the same color as well. The difference appears when the background is not white.

On the dark background (#1f2a30), the white-mixed color stayed rgb(163, 199, 239). The transparent-mixed color let the background show through and became rgb(28, 71, 114). The computed value of the transparent-mixed color was color(srgb 0.101961 0.45098 0.839216 / 0.4). The color itself is still --brand, and only the opacity has changed to 0.4.
If a button will sit on backgrounds of different colors and you want it to blend in, mix in transparent. If you want the same color on any background, mix in white.
The first CSS example uses a disabled color made by mixing 60% white in oklch. Placing white text on that color gives a contrast ratio of 1.72. WCAG 2.2 Success Criterion 1.4.3 requires a contrast ratio of at least 4.5:1 for text (3:1 for large text), but it does not set a contrast requirement for text in disabled components.
Write :hover before :disabled, or add :not(:disabled)
button:hover and button:disabled have the same specificity, 0-1-1, so whichever comes later wins. In the first CSS example, :disabled comes last, so a disabled button kept its disabled color even when hovered.
When I swapped the order and put :disabled first, hovering a disabled button changed its color to the hover color, oklch(0.476654 0.145889 255.232). A button that cannot be pressed ended up looking pressable.
If you don't want to depend on rule order, limit the hover rule to buttons that are not disabled.
button:hover:not(:disabled) {
--bg: color-mix(in oklch, var(--brand), black 15%);
}
With this rule, even if :disabled is written first, a disabled button keeps its disabled color when hovered. The :not(:disabled) hover rule does not match disabled buttons at all.
When the percentages don't add up to 100%
You can use two percentages that don't add up to 100%, even if you write both. The behavior I confirmed in the test environment is as follows.
| How it's written | Result |
|---|---|
#1a73d6, black (both omitted) |
Mixed at 50% each |
#1a73d6 80%, black 40% (total 120%) |
Mixed at a 2:1 ratio |
#1a73d6 30%, black 30% (total 60%) |
Mixed at 50% each, with an opacity of 0.6 |
#1a73d6, black 115% |
The declaration was invalid, so the earlier background: red was used |
When the total is below 100%, the missing part becomes transparent. MDN describes this as similar to mixing in transparent for the missing percentage. A percentage must be between 0% and 100%. A declaration with a value like 115% or -10% was ignored entirely.
Supported browsers
According to the compatibility data, these are the versions that support color-mix():
| Browser | First supported version |
|---|---|
| Chrome, Edge | 111 |
| Firefox | 113 |
| Safari (including iOS) | 16.2 |





