How to Style Disabled Inputs with :disabled in CSS
:disabled matches form fields that can't be used. input:disabled styles every disabled text box, so people can see at a glance which fields they can't change.
Syntax
<element>:disabled {
<declarations>
}
| Part | What it does |
|---|---|
<element> | The kind of field to style, such as input. Leave it out to match every disabled element. |
:disabled | Keeps only the disabled ones. It goes straight after <element>, with no space. |
<declarations> | The styles the disabled fields get. |
MDN's :disabled page says it represents any disabled element: one that can't be selected, clicked on, typed into or focused.
The Example
The example is a profile form with two text boxes: Name, which people can change, and Employee ID, which is disabled. One rule gives the disabled box a light grey background and a dashed border.
Step 1: Write the Code
Create a file named index.html in a text editor, such as Visual Studio Code:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>:disabled</title>
<style>
input:disabled {
background: #f5f5f5;
border: 1px dashed #bdbdbd;
}
</style>
</head>
<body>
<p><label>Name <input value="Ana"></label></p>
<p><label>Employee ID <input value="E-1024" disabled></label></p>
</body>
</html>
The disabled attribute disables the Employee ID box, and input:disabled matches it.
Step 2: Open It in a Browser
Double-click index.html. It opens in your browser:

The screenshot comes from Chromium 159, the open-source browser that Chrome is built on.
What Happened
- Employee ID has a light grey background and a dashed border. Chromium gave it the background
rgb(245, 245, 245), which is#f5f5f5, and a dashed border, because it's disabled. - Name kept the browser's own white box, because it isn't disabled.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Selecting the attribute: input[disabled] | It misses fields disabled another way: a text box inside <fieldset disabled> matched :disabled, but not [disabled] | Use :disabled |
Giving a field a class named disabled | A class doesn't disable anything, and a text box with class="disabled" didn't match :disabled | Add the disabled attribute |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| A field inside a disabled fieldset isn't styled | The rule uses [disabled] | Use :disabled |
| No field is styled | The fields aren't disabled | Add the disabled attribute to the field, or to the fieldset around the fields |
FAQ
Does it work for fields inside a disabled fieldset?
Yes. With <fieldset disabled>, the text box inside matched :disabled and got the dashed border, although it had no disabled attribute of its own.
Does it work for buttons and other form fields?
Yes. MDN's page says :disabled represents any disabled element, so button:disabled matches a disabled button the same way.
Conclusion
Add disabled to the fields people can't change, and style them with :disabled. It also catches fields disabled by a fieldset, which the [disabled] attribute selector misses.
Additional Resources
- :disabled, on MDN.
