Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

:disabled — disabled-element pseudo-class

The :disabled pseudo-class selects elements that are actually disabled under HTML rules, not just elements carrying a disabled attribute. It lets you style a control's state but does not itself disable the control.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

:disabled

The :disabled pseudo-class matches user-interface elements in a disabled state defined by the document language. In HTML, this covers actually disabled button, input, select, textarea, optgroup, option, and fieldset elements, plus form-associated custom elements. Writing button:disabled limits matching to buttons.

Do not equate :disabled with [disabled]: the latter selector only checks attribute presence. A control inside a disabled fieldset can match :disabled without its own disabled attribute. Disabling through that fieldset excludes descendants of its first legend child; those descendants can still be disabled for another reason. The example demonstrates this distinction.

The selector only detects state—a CSS rule does not disable a control. Properties such as display and visibility do not change matching against :disabled. Likewise, readonly alone does not mean disabled. :enabled is not equivalent to :not(:disabled) across all elements: an ordinary paragraph matches neither :enabled nor :disabled, but it does match :not(:disabled).

In the example, the inherited and direct buttons receive a red outline, and the text result is inherited, direct. The exception button benefits from the first-legend exception, while available remains enabled. The text result was verified in an isolated browser environment.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>:disabled example</title>
<style>
  button:disabled { outline: 3px solid #b00020; }
</style>
<fieldset disabled>
  <legend><button id="exception" type="button">Exception</button></legend>
  <button id="inherited" type="button">Inherited</button>
</fieldset>
<button id="direct" type="button" disabled>Direct</button>
<button id="available" type="button">Available</button>
<pre id="result"></pre>
<script>
  const ids = Array.from(document.querySelectorAll('button:disabled'),
    button => button.id);
  document.getElementById('result').textContent = ids.join(', ');
</script>
</html>

Result

inherited, direct

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources