CSS :disabled Selector

Beginner
⏱️ 5 min read
📚 Updated: Jul 2026
🎯 4 Examples
Form States

What You’ll Learn

The :disabled pseudo-class matches form elements that cannot be interacted with. Use it to give clear visual feedback when controls are temporarily or permanently unavailable.

01

Inactive

Not clickable.

02

Form controls

input, button.

03

vs :enabled

Opposite state.

04

Scoped

button:disabled.

05

Cursor

not-allowed.

06

A11y

Clear contrast.

Introduction

The :disabled selector in CSS is used to select form elements that are currently disabled — meaning they cannot be interacted with or modified by the user.

This pseudo-class is particularly useful for providing visual feedback on form controls that are temporarily or permanently unavailable, such as a submit button before form validation passes or a username field locked after registration.

Definition and Usage

Append :disabled to a selector with no space before the colon: :disabled, input:disabled, or button:disabled. Styles apply whenever the element has the HTML disabled attribute and disappear when it is removed.

💡
Beginner Tip

Add the disabled attribute in HTML to lock a control: <button disabled>. CSS :disabled styles it automatically — no JavaScript required for basic cases.

📝 Syntax

The syntax for the :disabled pseudo-class is:

syntax.css
:disabled {
  /* CSS properties */
}

Basic Example

disabled-form.css
/* Style for disabled elements */
:disabled {
  background-color: #f1f5f9;
  border: 2px solid #94a3b8;
  color: #94a3b8;
  cursor: not-allowed;
}

/* Style for enabled elements (contrast) */
:enabled {
  background-color: #ecfdf5;
  border: 2px solid #22c55e;
}
:disabled input:disabled button:disabled select:disabled

Supported Elements

ElementSupports disabled?
<input>Yes
<button>Yes
<select>, <textarea>Yes
<fieldset>, <optgroup>Yes (disables all child controls)
<div>, <span>No — use aria-disabled + a class instead

Syntax Rules

  • Requires the HTML disabled attribute on the element.
  • Combine with type selectors: input[type="email"]:disabled.
  • Pair with :enabled for clear enabled/disabled contrast.
  • Disabled elements cannot receive focus or submit form data.
  • fieldset[disabled] disables all controls inside the fieldset.

Related Selectors

  • :enabled — matches interactive form controls without disabled
  • :focus — disabled elements cannot receive focus
  • :hover — disabled elements typically ignore hover in browsers
  • :read-only — read-only fields can still be focused (different from disabled)
  • :default — matches the default option in a form group

⚡ Quick Reference

QuestionAnswer
Selector typePseudo-class
When it appliesElement has the disabled attribute
HTML trigger<input disabled> or <button disabled>
Common propertiesopacity, cursor: not-allowed, gray colors
Accessibility ruleProvide a clear, high-contrast disabled appearance
Browser supportAll modern browsers

When to Use :disabled

:disabled helps users understand which controls are unavailable:

  • Form validation — Gray out a submit button until required fields are filled.
  • Locked fields — Style username or ID fields that cannot be edited after signup.
  • Conditional forms — Disable sections until a prerequisite checkbox is checked.
  • Loading states — Disable buttons while a form is submitting to prevent double-clicks.
  • Permission restrictions — Show controls as inactive when the user lacks access.

👀 Live Preview

Disabled controls appear grayed out with a not-allowed cursor; enabled controls look normal:

Examples Gallery

Practice :disabled with login forms, button styling, opacity effects, and fieldset-wide disabling.

📜 Core Patterns

Style inactive form controls and contrast them with enabled ones.

Example 1 — Disabled login form field

Style a locked username field while keeping the password field and button interactive.

disabled-form.html
<style>
  :disabled {
    background-color: #f1f5f9;
    border: 2px solid #94a3b8;
    color: #94a3b8;
    cursor: not-allowed;
  }

  :enabled {
    background-color: #ecfdf5;
    border: 2px solid #22c55e;
  }
</style>

<form>
  <input type="text" placeholder="Username" disabled>
  <input type="password" placeholder="Password">
  <button type="submit">Login</button>
</form>
Try It Yourself

How It Works

The username field has the disabled attribute, so :disabled applies gray styling. The password field and button match :enabled and appear active.

Example 2 — Disabled button styling

Scope styles to buttons so disabled submit buttons look clearly inactive.

button-disabled.css
button:disabled {
  background-color: #cbd5e1;
  color: #64748b;
  border: none;
  padding: 0.6rem 1.2rem;
  border-radius: 0.5rem;
  cursor: not-allowed;
  opacity: 0.7;
}

button:enabled {
  background-color: #2563eb;
  color: #fff;
  cursor: pointer;
}
Try It Yourself

How It Works

button:disabled targets only disabled buttons. The gray background, reduced opacity, and cursor: not-allowed signal that the action is unavailable.

📄 Advanced Patterns

Extend disabled styling to inputs, selects, and entire fieldsets.

Example 3 — Input disabled with opacity

Use opacity alongside color changes for a softer disabled appearance on text inputs.

input-disabled.css
input:disabled {
  background-color: #f8fafc;
  border: 1px dashed #cbd5e1;
  color: #94a3b8;
  opacity: 0.65;
  cursor: not-allowed;
}

select:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}
Try It Yourself

How It Works

A dashed border and reduced opacity create a softer “locked” look. Ensure contrast still meets accessibility guidelines — do not rely on opacity alone.

Example 4 — Disabled fieldset

Disable an entire group of form controls by setting disabled on a <fieldset>.

fieldset-disabled.html
<style>
  fieldset:disabled {
    opacity: 0.6;
    border: 1px dashed #94a3b8;
    border-radius: 0.5rem;
    padding: 1rem;
  }

  fieldset:disabled :disabled {
    cursor: not-allowed;
  }
</style>

<fieldset disabled>
  <legend>Shipping (unavailable)</legend>
  <input type="text" placeholder="Address">
  <input type="text" placeholder="City">
</fieldset>
Try It Yourself

How It Works

When a fieldset is disabled, all nested form controls become disabled automatically. Style the fieldset container to show the entire section is inactive.

💬 Usage Tips

  • Use :disabled alongside :enabled to create distinct styles for both states.
  • Add the disabled attribute in HTML — CSS will apply automatically without JavaScript.
  • Combine with element selectors (input:disabled, button:disabled) for precise targeting.
  • Set cursor: not-allowed on disabled controls for immediate visual feedback.
  • Toggle the disabled attribute with JavaScript for dynamic form validation.

⚠️ Common Pitfalls

  • Non-form elements:disabled does not apply to <div> or <span>. Use a class for custom components.
  • Subtle styling only — Light gray on white may be hard to see. Ensure enough contrast for all users.
  • aria-disabled alone — CSS :disabled does not match aria-disabled="true" without the HTML disabled attribute.
  • Disabled vs read-only — Read-only fields can still be focused; disabled fields cannot.
  • Excluding from forms — Disabled controls are not submitted with form data.

♿ Accessibility

  • Visual contrast — Disabled controls must look clearly different from enabled ones.
  • Do not rely on color alone — Combine color, opacity, cursor, and labels to indicate state.
  • Screen readers — The disabled attribute is announced automatically; avoid removing it.
  • Explain why — Add helper text near disabled fields explaining why they are locked.
  • Focus behavior — Disabled elements are skipped in tab order, which is correct behavior.

🧠 How :disabled Works

1

Element gets disabled attribute

HTML disabled is added in markup or via JavaScript.

HTML
2

Browser blocks interaction

The control cannot be clicked, typed into, or focused. It is excluded from form submission.

Block
3

:disabled styles apply

Your CSS gray-out, opacity, and cursor rules take effect.

Style
=

Clear inactive state

Users know which controls they cannot use.

🖥 Browser Compatibility

The :disabled pseudo-class is supported in all modern browsers on form controls.

Baseline · Universal support

Disabled styling everywhere

:disabled works reliably in Chrome, Firefox, Safari, Edge, and Opera.

99% Universal support
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions
Full support
Opera All modern versions
Full support
:disabled pseudo-class 99% supported

Bottom line: :disabled is safe to use on all form controls in every modern browser.

🎉 Conclusion

The :disabled selector is essential for controlling the appearance of form elements that cannot be interacted with. By applying appropriate styles, you ensure users know which controls are inactive and prevent confusion during form submission.

Pair it with :enabled, use clear visual contrast, and always include the HTML disabled attribute for proper behavior and accessibility.

💡 Best Practices

✅ Do

  • Use high-contrast gray styling for disabled controls
  • Set cursor: not-allowed on disabled buttons
  • Pair with :enabled for clear state contrast
  • Use the HTML disabled attribute, not just CSS
  • Explain why a field is disabled with helper text

❌ Don’t

  • Apply :disabled styling to non-form elements
  • Rely on subtle color changes alone
  • Expect :disabled to match aria-disabled alone
  • Confuse disabled with read-only states
  • Forget disabled fields are not submitted

Key Takeaways

Knowledge Unlocked

Five things to remember about :disabled

Use these points when styling inactive form controls.

5
Core concepts
HTML 02

disabled attr

HTML trigger.

Markup
vs 03

:enabled

Opposite state.

Pair
👆 04

not-allowed

Cursor cue.

UX
🌐 05

99% support

All browsers.

Compat

❓ Frequently Asked Questions

The :disabled pseudo-class matches form elements that cannot be interacted with — they have the disabled attribute set or are otherwise inactive, such as a grayed-out submit button.
Form controls that support the disabled attribute: input, button, select, textarea, fieldset, and optgroup. Non-form elements like div and span cannot use :disabled unless given a disabled attribute (which has no effect on them).
:disabled matches inactive form controls. :enabled matches the opposite — controls without the disabled attribute that users can interact with.
No. CSS :disabled only matches elements with the HTML disabled attribute. Elements with only aria-disabled="true" need a class or attribute selector unless they also have the disabled attribute.
Yes. All modern browsers support :disabled on form controls. It has been available since CSS3.

Practice in the Live Editor

Open the HTML editor and experiment with :disabled, form states, and button styling.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful