:enabled
Example
button:hover {
background: #0047b3;
}button:enabled:hover {
background: #0047b3;
}Adding :enabled stops disabled buttons from reacting to hover, so they don't look clickable.
Common mistakes
- Expecting
:enabledto match custom controls built fromdivelements. - Forgetting that buttons with
aria-disabled='true'still match:enabled.
Key points
:enabledstyles target form controls likebutton:enabledorinput:enabled, not plaindivs.- Hover effects on buttons use
button:enabled:hoverso 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.