CSS Reference ยท Pseudo-classes
The :enabled pseudo-class
Reference for the CSS :enabled pseudo-class: match form controls that can be focused and used, how it pairs with :disabled, plus examples and caveats.
The :enabled pseudo-class matches form controls that can be used: they can be focused, clicked, edited and submitted. It is the exact opposite of :disabled among elements that can be disabled.
It is handy for adding hover or cursor styles only to controls that actually react, so a disabled button does not look clickable.
CSS
button:enabled:hover { background: #1d4ed8; }
Try it
Syntax
CSS
:enabled { /* declarations */ }
- Applies to:
<button>,<input>,<select>,<textarea>,<optgroup>,<option>,<fieldset>and form-associated custom elements. - Specificity: (0,1,0).
- Inherited / animatable: not applicable.
Values
| Syntax and arguments | Description |
|---|---|
:enabled |
No arguments. Matches an element that can be disabled but is not. |
Usage notes
- Only disableable elements. A
<div>or<a>is neither:enablednor:disabled. The pseudo-class does not mean "anything that is not disabled". :enabledvs:not(:disabled). On form controls they match the same elements.:not(:disabled)also matches every other element, which is rarely what you want.- Specificity trap.
button:enabledis more specific thanbutton, so it can override your base rules. Keep that in mind when you later add.primarystyles. - Read-only is still enabled. An input with
readonlyis enabled; use:read-onlyto tell them apart. - Fieldsets. Controls inside a disabled
<fieldset>are disabled, so they do not match.
Browser support
Supported in every browser.
Related
:disabled:read-write:hover- Lesson: Styling Forms