HTML Disabled vs Readonly Form Controls
Disable a control
disabled prevents normal interaction and excludes the control from the form entry list and constraint validation. Its value may still be present in the DOM.
<form> <label> Unavailable <input name="item" value="A" disabled> </label></form>The value is visible but FormData excludes item.
Make a field read-only
readonly prevents ordinary editing for supported text-like inputs and textarea, but normally permits focus and submission of named values. It bars the control from constraint validation. It does not apply to select, checkbox or radio.
<form> <label> Order ID <input name="order" value="A01" readonly> </label></form>The entry order=A01 is included and willValidate is false.
Disable a group
A disabled fieldset disables descendant form controls except those inside its first legend child. The disabled property on a descendant need not reflect the inherited disabled state; the :disabled selector reflects effective disabledness.
<form> <fieldset disabled> <legend> Options <label> <input type="checkbox" name="keep" checked> Keep </label> </legend> <label> Extra <input name="extra" value="B"> </label> </fieldset></form>keep remains included; extra is excluded.
Common mistakes and practice
Neither attribute is an authorization mechanism: the server must determine which fields the user may change. Avoid readonly on unsupported controls. For a field that must be submitted, do not disable it merely to prevent typing.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
HTML Disabled vs Readonly Form Controls — Knowledge Check
Apply the control concepts taught in this lesson.
Which named control is normally excluded from submission?
Which property is suitable for a text field that must be submitted but not edited?
Which control does readonly not apply to?
Which descendant is exempt from a disabled fieldset?
Does readonly prevent a malicious change to server data?