readonly (HTML attribute)

Spec
Depr. Version
No HTML 3.02
Browser support (more…)
IE5.5+ FF1+ SA1.3+ OP9.2+ CH2+
Full Full Full Full Full

Syntax

readonly="readonly"

Description

The "readonly" attribute stops the user from changing the value of an input (in the case of a text input or password), but doesn’t prevent the user from interacting with the form control content. It’s still possible for the user to click inside the input, tab to it, highlight the text inside it, and even copy and paste that content—it’s just that the value can’t be changed or cleared.

This attribute is most commonly used to stop the user from interfering with the value of a text input until some other condition has been met (for example, until a checkbox is ticked to confirm the user’s acceptance of terms and conditions). At that point, JavaScript would be required to removed the "readonly" value, making the form control completely usable.

Example

This readonly attribute prevents the input value of "Southampton" from being changed:
<form>
  <label for="town">Postal Town:</label>
  <input type="text" name="town" id="town" readonly="readonly"
      value="Southampton"/>
</form>

Value

"readonly" is the only possible value for this attribute.

Compatibility

Internet Explorer Firefox Safari Opera Chrome
5.5 6.0 7.0 8.0 1.0 1.5 2.0 3.0 3.5 1.3 2.0 3.1 4.0 9.2 9.5 10.0 2.0
Full Full Full Full Full Full Full Full Full Full Full Full Full Full Full Full Full

This attribute has good support, but there are slight implementation differences from browser-to-browser depending on the type of input it’s dealing with.

User-contributed notes

Related Products