HTML <input> readonlyAttribute

HTML input 标签参考手册HTML <input> Tag

Examples

An HTML form with a read-only input field:

<form action="demo_form.html">
  Country: <input type="text" name="country" value="Norway" readonly><br>
<input type="submit" value="Submit">
</form>

Try it Yourself »

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the readonly attribute.


Definition and Usage

The readonly attribute is a boolean attribute.

The readonly attribute specifies that an input field is read-only.

A read-only field cannot be modified. However, users can still use the Tab key to switch to the field, and can also select or copy its text.

The readonly attribute can prevent users from modifying the value until certain conditions are met (for example, selecting a checkbox). Then, JavaScript is needed to remove the readonly value and switch the input field to an editable state.


Differences between HTML 4.01 and HTML5

None.


Differences between HTML and XHTML

In XHTML, attribute minimization is forbidden, and the readonly attribute must be defined as <input readonly="readonly" />.


Syntax

<input readonly>


HTML input 标签参考手册HTML <input> Tag Other Extensions