:enabled

Term side of the Card.
Topic: Pseudo Classes
Unit title: :enabled
Categories: Pseudo-class
Explanation side of the Card

Explanation: The pseudo-class that targets form elements that are active and can be interacted with by the user. It's the opposite of `:disabled` pseudo-class and is often used to style inputs, buttons or other controls that are ready for user input.

Browser compatibility:
  • The chrome browser supports this feature starting from version 1.
  • The edge browser supports this feature starting from version 12.
  • The firefox browser supports this feature starting from version 1.
  • The safari browser supports this feature starting from version 3.1.
Availability: 

Example

Wrongcss
button:hover {
  background: #0047b3;
}
Rightcss
button:enabled:hover {
  background: #0047b3;
}

Adding :enabled stops disabled buttons from reacting to hover, so they don't look clickable.

Common mistakes

  • Expecting :enabled to match custom controls built from div elements.
  • Forgetting that buttons with aria-disabled='true' still match :enabled.

Key points

  • :enabled styles target form controls like button:enabled or input:enabled, not plain divs.
  • Hover effects on buttons use button:enabled:hover so disabled buttons don't react.

Interview questions

Is :enabled the opposite of :disabled?

Yes, for elements that can be disabled. Elements that can't be disabled, like div, match neither.

Is :enabled the same as :not(:disabled)?

No. :not(:disabled) also matches elements like div, while :enabled matches only elements that can be disabled.

Analytics cookiesWe'd like to use analytics cookies to see which pages are useful. They're set only if you accept. Privacy Policy