Encodera

Thanks for reading!

Donate to the site — we work hard for you.

HTML & CSS reference

:disabled

Matches form elements with the `disabled` attribute; `:enabled` matches the active ones.

Syntax

selector:disabled { … }

Examples

A disabled button looks inactive:

<style>
  button { padding: 8px 16px; background: royalblue; color: white; border: 0; }
  button:disabled { background: lightgray; color: gray; cursor: not-allowed; }
</style>
 
<button>Send</button>
<button disabled>Send</button>

Notes

Keep enough contrast on disabled elements so the text can still be read. A disabled field is not sent with the form; if you only need to prevent editing, use readonly and :read-only.

See also

  • :checked — Matches a checked checkbox or radio button, and a selected `<option>`.
  • cursor — The look of the mouse pointer over the element.
  • <button> — A button: submits a form or triggers an action.

Related recipes

In the tutorial

  • Styling forms — How to style fields and buttons — padding and borders, the focus state, placeholder, disabled and invalid fields, accent-color and custom checkboxes with appearance: none.

Thanks for reading!

Donate to the site — we work hard for you.