HTML disabled Attribute

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 3 Examples
Forms & Input

What You’ll Learn

The disabled attribute is a boolean attribute that turns off user interaction on form controls. When present, the control cannot be clicked, typed in, or focused, and its value is not sent when the form is submitted. It is essential for guiding users and preventing invalid actions.

01

Boolean

Presence = off.

02

No Submit

Excluded from form.

03

Buttons

Block clicks.

04

Inputs

Block editing.

05

fieldset

Disable a group.

06

JavaScript

.disabled = true.

Purpose of disabled

The primary purpose of the disabled attribute is to prevent user interaction with a form control when it should not be used. Common cases include a submit button that stays disabled until required fields are filled, shipping fields hidden when pickup is selected, or options that do not apply to the current form state.

Disabled controls are visually de-emphasized by browsers (often grayed out) and are removed from the tab order. They also skip HTML constraint validation and are not included in form submission data.

💡
Not the same as readonly

readonly fields can still be focused and submitted. Use disabled when the user should not interact at all or when the value must not be sent.

📝 Syntax

Add the disabled attribute to any supported form control:

disabled.html
<form>

  <input type="text" name="username">

  <button type="submit" disabled>Submit</button>

</form>

Syntax Rules

  • Boolean attribute: write disabled alone or as disabled="".
  • In JavaScript, use element.disabled = true or false.
  • Do not use non-empty values like disabled="true" in HTML (browsers treat any presence as disabled).
  • A disabled <fieldset> disables all nested controls except the legend in some cases.

💎 Values

The disabled attribute is a boolean attribute. It has no meaningful string values:

  • Attribute present — Control is disabled (no interaction, not submitted).
  • Attribute absent — Control is enabled and behaves normally.
disabled-boolean.html
<!-- Recommended -->

<button disabled>Save</button>



<!-- Also valid (XHTML-style) -->

<button disabled="">Save</button>



<!-- JavaScript -->

<script>btn.disabled = true;</script>

⚡ Quick Reference

BehaviorWhen disabledNotes
Click / typeBlockedNo user input
FocusNot focusableSkipped in tab order
Form submitValue not sentNot a successful control
ValidationSkippedNo constraint checks
JS propertyelement.disabledtrue or false
fieldsetDisables descendantsGroup entire section

Applicable Elements

ElementSupported?Notes
<button>YesCommon for conditional submit
<input>YesAll input types
<select>, <option>, <optgroup>YesDisable choices or groups
<textarea>YesBlock editing
<fieldset>YesDisables all nested controls
<div>, <a>NoUse aria-disabled + JS for non-form UI

disabled vs readonly

Featuredisabledreadonly
User can focusNoYes
User can editNoNo
Submitted with formNoYes
Typical useUnavailable controlsDisplay-only values
Valid onMost form controlstext-like inputs, textarea

Examples Gallery

Disabled submit buttons, JavaScript toggling, and fieldset groups with readonly comparison.

Example — Disabled Submit Button

A login form with the submit button disabled until inputs are ready:

disabled-form.html
<form>

  <label for="username">Username</label>

  <input type="text" id="username" name="username">



  <label for="password">Password</label>

  <input type="password" id="password" name="password">



  <button type="submit" disabled>Submit</button>

</form>
Try It Yourself

How It Works

The submit button is inactive until your script or validation removes the disabled attribute or sets disabled = false.

Dynamic Values with JavaScript

Enable the submit button when the name field is not empty:

toggle-disabled.html
<input type="text" id="name">

<button type="submit" id="submitBtn" disabled>Submit</button>



<script>

  nameInput.addEventListener("input", function () {

    submitButton.disabled = nameInput.value.trim() === "";

  });

</script>
Try It Yourself

How It Works

The script sets submitButton.disabled based on input. Prefer the boolean property over string attributes in JavaScript.

Example — Disabled fieldset

Disable an entire group of controls at once:

fieldset-disabled.html
<fieldset disabled>

  <legend>Shipping</legend>

  <input type="text" name="city">

  <input type="text" name="zip">

</fieldset>

How It Works

A disabled <fieldset> disables every control inside it. None of those values are submitted with the form.

♿ Accessibility

  • Use native disabled on form controls — Browsers expose disabled state to assistive technology automatically.
  • Explain why controls are disabled — Add helper text near grayed-out fields so users know what to do next.
  • Do not rely on color alone — Pair visual styling with clear labels and instructions.
  • Avoid disabling the only path forward — Tell users how to enable the control (e.g. “Fill required fields”).
  • For non-form elements — Use aria-disabled="true" and block pointer events with JavaScript; native disabled does not apply to <div> or <a>.

🧠 How disabled Works

1

Author adds disabled

Mark control or fieldset as inactive in HTML or JS.

Markup
2

Browser blocks interaction

No click, type, or focus; skipped in tab order.

UX
3

Form submits

Disabled controls omitted from submission data.

Submit
=

Safer, clearer forms

Users cannot trigger invalid or unavailable actions.

Browser Support

The disabled attribute is supported in all modern browsers and has been part of HTML forms for many years.

HTML4+ · Fully supported

Universal form control state

All major browsers honor disabled on buttons, inputs, selects, textareas, and fieldsets.

99% Browser support
Google Chrome Fully supported
Full support
Mozilla Firefox Fully supported
Full support
Apple Safari Fully supported
Full support
Microsoft Edge Fully supported
Full support
disabled attribute 99% supported

Bottom line: Use disabled confidently on form controls in all modern projects.

💡 Best Practices

✅ Do

  • Disable submit until required fields are valid
  • Use fieldset disabled for whole sections
  • Explain why a control is disabled
  • Use element.disabled in JavaScript
  • Style :disabled for clear visual feedback

❌ Don’t

  • Disable fields you still need submitted
  • Confuse disabled with readonly
  • Leave users stuck with no instructions
  • Put disabled on div or anchor for forms
  • Rely on disabled="true" as special HTML syntax

Conclusion

The disabled attribute is a valuable tool for controlling form element state. It blocks interaction, removes controls from the tab order, and excludes values from submission.

Use it to guide users toward valid actions, disable entire groups with <fieldset disabled>, and toggle state dynamically with JavaScript when conditions change.

Key Takeaways

Knowledge Unlocked

Five truths every developer should know about disabled

Bookmark these before your next form.

5
Core concepts
🚫 02

No Submit

Not sent.

Forms
⌨️ 03

No Focus

Tab skipped.

Behavior
📝 04

fieldset

Group disable.

Pattern
↔️ 05

vs readonly

Different rules.

Compare

❓ Frequently Asked Questions

It prevents user interaction with a form control. Disabled elements cannot be focused, edited, or activated.
No. Disabled controls are not successful controls and their values are excluded from form submission.
button, input, select, textarea, option, optgroup, and fieldset.
readonly prevents editing but still submits. disabled blocks all interaction and excludes the value from submission.
Set element.disabled = true or false, or use setAttribute("disabled", "") and removeAttribute("disabled").
Yes. The disabled attribute has universal support on form controls across all modern and legacy browsers.

Control form state with disabled

Practice disabling submit buttons and toggling disabled with JavaScript in the Try It editor.

Try JavaScript toggle →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

3 people found this page helpful