HTML readonly Attribute

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The readonly attribute is a Boolean on textual <input> types and <textarea>. When present, the user cannot edit the control — but it stays focusable, and its value is still submitted with the form.

Contrast with disabled: disabled controls typically cannot focus and are left out of submission. Use readonly for confirmed values (order ID, username) that must still post to the server.

Baseline · Widely available.

Not deprecated. Boolean: presence means on. Write readonly, not readonly="false".

Do not combine with required.

Readonly controls do not participate in constraint validation. MDN: required is not permitted with readonly.

HTML Syntax

syntax.html
<input type="text" readonly>
<textarea readonly> …</textarea>

In JavaScript: input.readOnly = true (capital O in the IDL property).

Attribute Values

Boolean — no value list. Behavior vs related states:

StateEditableFocusSubmittedTry it
NormalYesYesYesTry it
readonlyNoYesYesTry it
disabledNoNoNoTry it
textarea + readonlyNoYesYesTry it

Live Preview

Toggle readonly on the field. Try typing, then Tab to confirm it still focuses when readonly.

Field

Readonly = not editable, still focusable. Disabled (compare Example 2) would skip focus and submit.

State

readOnly: true

HTML Examples

Short demos. Use Try It Yourself for a live editor.

Example 1 — Readonly Text Input

Show a fixed value the user can select/copy but not change.

HTML
<label for="order">Order ID</label>
<input id="order" name="order" type="text"
  value="ORD-1042" readonly>
Try It Yourself

How It Works

  1. readonly is present on the text input.
  2. User cannot type a new value.
  3. Focus / select / copy still work.
  4. On submit, order=ORD-1042 is included.

Example 2 — Readonly vs Disabled

Same value; only the readonly field is submitted.

HTML
<form action="#" method="get">
  <label for="a">Readonly</label>
  <input id="a" name="a" value="kept" readonly>

  <label for="b">Disabled</label>
  <input id="b" name="b" value="dropped" disabled>

  <button type="submit">Submit</button>
</form>
Try It Yourself

How It Works

  1. readonly field stays in the form data.
  2. disabled field is skipped on submit.
  3. Tab order reaches readonly, not disabled.
  4. Pick readonly when the value must post.

Example 3 — Readonly Textarea

Display multi-line text that cannot be edited in the UI.

HTML
<label for="terms">Terms (read only)</label>
<textarea id="terms" name="terms" rows="4" readonly>
These terms are shown for review and will be submitted with the form.
</textarea>
Try It Yourself

How It Works

  1. textarea supports the same Boolean attribute.
  2. Content is visible and selectable.
  3. Typing does not change the text.
  4. name + value still submit with the form.

Edge Cases & Pitfalls

Most mistakes are using the wrong control type or confusing readonly with disabled.

types

Not for checkbox, radio, file, etc.

Only textual inputs and textarea. Use disabled (or redesign) for other controls.

boolean

readonly="false" still means readonly

Remove the attribute or set readOnly = false in script.

required

Skip required on readonly fields

They do not join constraint validation; pairing is invalid per MDN guidance.

script

Scripts can still change the value

Readonly blocks user editing, not programmatic updates.

css

Style with :read-only

Use the :read-only / :read-write pseudo-classes for visual feedback.

Browser Support

readonly is an HTML Boolean attribute on form controls. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

readonly

Supported everywhere modern forms work. Prefer readonly over disabled when the value must still submit.

98% Global support (approx.)
Google Chrome Yes
Full support
Mozilla Firefox Yes
Full support
Apple Safari Yes
Full support
Microsoft Edge Yes
Full support
Opera Yes
Full support
Samsung Internet Yes
Full support
Internet Explorer Yes
Supported
readonly Widely supported

Bottom line: Safe to use on text-like inputs and textarea. Remember: focusable + submitted, unlike disabled.

Key Takeaways

  • Role: non-editable, still focusable and submitted.
  • Not disabled — disabled skips focus and submit.
  • Textual inputs + textarea only.
  • Avoid pairing with required.

One line: readonly locks editing but keeps the field in focus order and form data.

Frequently Asked Questions

It is a Boolean attribute on textual inputs and textarea. When present, the user cannot edit the control, but it can still receive focus and its value is submitted with the form.
Readonly fields stay focusable and are submitted. Disabled fields usually look inactive, cannot receive focus, and are omitted from form submission.
Text-like inputs (text, search, tel, url, email, password, date types, number, and similar) and textarea. It does not apply to checkbox, radio, file, range, color, hidden, or button types.
No meaningful effect. MDN notes required is not permitted together with readonly, and readonly controls do not participate in constraint validation.
Yes. Scripts can set the value or toggle input.readOnly / remove the attribute. Users cannot edit through the UI while readonly is set.
No. It is a Baseline widely available Boolean form attribute.

Next: referrerpolicy

Control which referrer is sent when fetching linked resources.

referrerpolicy tutorial →

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.

8 people found this page helpful