How to style a disabled button in CSS
Styling a disabled button looks like a one-line job, and mostly it is. The details are where it goes wrong: hover styles that still fire, a cursor that won't show, and buttons that need to stay focusable.
The short answer
To style a disabled button in CSS, use the :disabled pseudo-class. It matches any button that has the disabled attribute, and it has worked in every major browser for years, so there's no fallback to write.
button:disabled {
background: #e5e7eb;
color: #6b7280;
cursor: not-allowed;
}That covers most cases. The rest of this guide is about the details that trip people up: hover styles that still fire, a cursor that won't show, buttons that need to stay focusable, and whole forms that switch off at once.
How :disabled decides what matches
The selector follows the HTML. A button matches :disabled when it has the disabled attribute, and stops matching the moment the attribute is removed, so JavaScript only has to toggle the attribute and the styles follow on their own.
<button disabled>Save</button>The disabled state isn't just visual. The browser takes the button out of the tab order and it won't fire click events, so it can't be submitted by accident. That's the main reason to use the real attribute instead of a .disabled class: a class changes how the button looks, while the attribute changes how it behaves.
The same pseudo-class works on input, select, textarea, option, optgroup and fieldset. Our :disabled reference has the full support table.
Keep hover styles off disabled buttons
A common bug: the button looks disabled, but it still darkens on hover because the hover rule comes later in the stylesheet. The fix is to scope interactive states to :enabled, the opposite of :disabled:
button {
background: oklch(55% 0.18 260);
color: white;
}
button:enabled:hover {
background: oklch(48% 0.18 260);
}Now the hover color only applies to buttons that can actually be pressed, and there's no need for a second rule that undoes it.
Why cursor: not-allowed sometimes disappears
The cursor: not-allowed line is the usual way to say "you can't click this". It stops working when the same rule also sets pointer-events: none, because the button then ignores the mouse completely and the cursor never changes:
button:disabled {
cursor: not-allowed;
pointer-events: none;
}A real disabled button already ignores clicks, so pointer-events: none isn't needed on it. Leave it off and the cursor shows up again.
Buttons that should stay focusable
Sometimes a disabled button needs to stay reachable by keyboard, for example so a tooltip can explain why it's off. The disabled attribute removes it from the tab order, so some design systems use aria-disabled="true" instead and style that attribute directly:
<button aria-disabled="true">Save</button>
button[aria-disabled="true"] {
opacity: 0.6;
cursor: not-allowed;
}The tradeoff is that aria-disabled only tells assistive technology the button is unavailable. The button still receives clicks, so the click handler has to check the attribute and stop the action itself.
Disable a whole form at once
Putting disabled on a fieldset disables every form control inside it (except those inside its first legend), and each of those controls matches :disabled. That's handy while a form is saving:
<fieldset disabled>
<input name="email">
<button>Subscribe</button>
</fieldset>To style the container based on its buttons, :has() works too. It's been supported in all major browsers since Firefox added it in December 2023:
form:has(button:disabled) {
opacity: 0.8;
}Making disabled buttons readable
Grey text on a grey button is the classic disabled look, and WCAG's contrast rule for text doesn't apply to inactive controls. Readable is still kinder, though: the label should say what the button does, even when it's off. Many teams lower the contrast a little and keep the text legible, rather than dropping the whole button to a low opacity.
Color alone also isn't a strong signal for everyone. Pairing the color change with cursor: not-allowed and a short hint near the button, like "Fill in your email to continue", makes the state clear without relying on how well someone sees grey.