CSS :enabled
Pseudo-Class
The :enabled
pseudo-class selects and styles form elements that are enabled (i.e., elements that do not have the disabled
attribute). This is useful for highlighting interactive inputs and buttons.
1. Syntax
✅ Styles enabled input fields with a green border.
2. Example – Styling Enabled Form Elements
✅ Enabled inputs & buttons have a blue border.
✅ Disabled elements are grayed out with a not-allowed
cursor.
3. Use Case – Highlight Active Fields
✅ When an enabled input field is focused, it gets an orange glow.
4. :enabled
vs [disabled]
Attribute Selector
Feature | :enabled | [disabled] |
---|---|---|
Dynamic? | Yes, updates automatically | No, applies only to hardcoded attributes |
Specificity | Lower | Higher |
✅ Use :enabled
for dynamic elements that change state.
5. Browser Support
✅ Fully supported in Chrome, Edge, Firefox, Safari, and Opera.
6. Best Practices
✔ Use :enabled
to make interactive elements stand out.
✔ Combine with :focus
for better user experience.
✔ Use JavaScript to dynamically enable/disable elements