👀 Live Preview
Try to edit — the field is readonly but you can focus and select text:
You can tab to this field and copy the value, but you cannot type changes.

The readonly attribute makes a form field non-editable while keeping it focusable and included in form submission. Use it to show values users should see but not change — like an order ID, account email on a profile page, or a pre-filled shipping address. Unlike disabled, readonly fields can be tabbed to, selected, and copied. Set element.readOnly = true in JavaScript (note camelCase). Readonly is not a security control — always validate on the server.
View only.
Tab + copy.
With form.
Key diff.
JS property.
true/false.
readonly AttributeForms often need to display data the user should not accidentally change — a username on a settings page, a reference number on a checkout form, or a calculated total. The readonly attribute prevents typing and editing while still showing the value clearly and sending it when the form submits.
Choose readonly over disabled when the value must reach the server. Choose disabled when the control should be completely inactive or excluded from submission.
readonly only blocks casual UI editing. Users can modify values in DevTools or HTTP requests. Never rely on it to protect sensitive data — validate server-side.
Add readonly as a boolean attribute on supported inputs or textarea:
<label for="username">Username:</label>
<input type="text" id="username" name="username"
value="jane_doe" readonly>
<label for="orderId">Order ID:</label>
<input type="text" id="orderId" name="orderId"
value="ORD-1042" readonly="readonly">
<textarea id="notes" name="notes" readonly>Pre-filled note.</textarea>readonly or readonly="readonly".readOnly = false in JS to make the field editable again.input types and textarea.checkbox, radio, select, button, or file.readOnly (camelCase), not readonly.The readonly attribute is a boolean — it has no meaningful string values:
readonly — Field is read-only (most common).readonly="readonly" — XHTML-style equivalent.element.readOnly = true / false — JavaScript toggle.<!-- Boolean presence -->
<input type="email" value="user@example.com" readonly>
<!-- JavaScript -->
<script>
input.readOnly = true; // lock
input.readOnly = false; // unlock
</script>| Concept | readonly | disabled |
|---|---|---|
| User can edit | No | No |
| User can focus | Yes | No |
| Submitted with form | Yes | No |
| JS property | readOnly | disabled |
| Typical use | Display-only values | Unavailable controls |
| Valid on | text-like input, textarea | Most form controls |
| Element / type | Supported? | Notes |
|---|---|---|
<input type="text"> | Yes | Most common |
email, password, tel, url, search | Yes | Text-entry types |
number, date, time, datetime-local | Yes | Picker inputs |
<textarea> | Yes | Multi-line text |
checkbox, radio, file | No | Use disabled instead |
<select>, <button> | No | Not applicable |
readonly vs disabled vs value| Feature | readonly | disabled | value |
|---|---|---|---|
| Prevents editing | Yes | Yes | No |
| Focusable | Yes | No | Yes |
| Form submission | Included | Excluded | Included |
| Purpose | Lock UI editing | Deactivate control | Field content |
Read-only form fields, toggling readOnly in JavaScript, and comparing submission behavior with disabled.
Try to edit — the field is readonly but you can focus and select text:
You can tab to this field and copy the value, but you cannot type changes.
Display account info users should see but not edit:
<form>
<label for="username">Username:</label>
<input type="text" id="username" name="username"
value="jane_doe" readonly>
<label for="email">Email:</label>
<input type="email" id="email" name="email"
value="jane@example.com" readonly>
<label for="comments">Notes:</label>
<textarea id="comments" name="comments" readonly>Account created on Jan 2025.</textarea>
<button type="submit">Save changes</button>
</form>All three fields are non-editable but remain in the tab order and submit their values when the form is posted.
Toggle read-only state when conditions change:
<input type="text" id="dynamicField" value="Editable until locked">
<button type="button" id="lockBtn">Lock field</button>
<script>
document.getElementById("lockBtn").addEventListener("click", function () {
document.getElementById("dynamicField").readOnly = true;
});
</script>The IDL property is readOnly (camelCase). Set false or remove the attribute to unlock editing again.
Readonly values submit; disabled values do not:
<form id="demoForm">
<input type="text" name="readonlyField" value="kept" readonly>
<input type="text" name="disabledField" value="dropped" disabled>
<button type="submit">Submit</button>
</form>This is the most important practical difference. Use readonly when the server needs the value; use disabled when it should not be sent.
disabled on buttons and toggles instead.<label>.readonly present.
Edit blocked.
Tab + copy.
Value sent.
The readonly attribute on supported input types and textarea works in all modern browsers.
readonly supportRead-only fields work consistently across browsers on text-like inputs and textarea.
Bottom line: Safe for read-only text fields and textareas in all modern browsers.
readonly for display-only values that must submitreadOnly in JS when toggling based on user permissionsreadonly with disabled submission ruleselement.readonly in JS — the property is readOnlyThe readonly attribute locks form fields against editing while keeping them focusable and submittable — ideal for showing fixed account or order data.
Choose it over disabled when the server needs the value, and always validate on the backend.
readonlyBookmark these before building forms.
UI locked.
RoleUnlike disabled.
FormsTab + copy.
UXcamelCase JS.
APIServer validate.
Gotchareadonly blocks editing but keeps focus and submission. disabled blocks all interaction and excludes the value from the POST body.input types and textarea. Not checkbox, radio, select, or button.element.readOnly = true — note camelCase. Set false to unlock.textarea in all modern browsers.Practice readonly on profile forms, JavaScript toggles, and readonly-vs-disabled submission in the Try It editor.
5 people found this page helpful