CSS

Disabled Button Styles in CSS (:disabled)

A disabled button is styled with the :disabled pseudo-class. The usual treatment is a lighter, desaturated look and a not-allowed cursor, so people can see at a glance that it can’t be clicked.

Demo:

Basic disabled button

Give disabled buttons their own colors instead of only lowering the opacity: a gray background with dark gray text stays readable, while 50% opacity on a colored button often doesn’t. Exclude disabled buttons from the hover style so they don’t react to the mouse.

css
.button:disabled {
  background: #cbd5e1;
  color: #475569;
  cursor: not-allowed;
}

.button:hover:not(:disabled) {
  background: #1e40af;
}

disabled vs aria-disabled

The disabled attribute removes the button from keyboard navigation entirely, and it ignores clicks. Screen reader users who tab through the form never find it, and can’t learn why they can’t continue. aria-disabled="true" keeps the button focusable and announced as disabled, so you can explain what’s missing. You then block the click in JavaScript yourself.

html
<button class="button" aria-disabled="true" aria-describedby="hint">Continue</button>
<p id="hint">Accept the terms to continue.</p>

<script>
  document.querySelectorAll('[aria-disabled="true"]').forEach((btn) => {
    btn.addEventListener('click', (e) => e.preventDefault());
  });
</script>

Loading button

While a form submits, disable the button to prevent double submissions and show that something is happening. A small spinner from a ::before pseudo-element needs no extra markup.

css
.button.is-loading::before {
  content: "";
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 8px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { rotate: 360deg; }
}

Disabled links

Links can’t be disabled with an attribute. If something must look disabled and not be clickable, use a button, or block the link with pointer-events: none plus aria-disabled. pointer-events alone doesn’t stop keyboard users.

css
a[aria-disabled="true"] {
  color: #94a3b8;
  pointer-events: none;
  text-decoration: none;
}

FAQ

How do I style a disabled button in CSS?
Use button:disabled { ... }, typically with a gray background, muted text color and cursor: not-allowed.

Why doesn’t cursor: not-allowed show on my disabled button?
Some resets set pointer-events: none on disabled buttons, which also hides the cursor. Remove that rule.

Do disabled buttons need good contrast?
WCAG doesn’t require contrast for disabled controls, but people still need to read the label to understand what they can’t do yet. Keep it legible.

Need a styled button to start from? The CSS buttons generator has over 100 designs with copy-paste code.

Did you like this CSS code snippet? Share it with your friends:
Want to learn more? Ask your AI: