HTML readonly Attribute

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 3 Examples
Forms & Validation

Introduction

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.

What You’ll Learn

01

No editing

View only.

02

Can focus

Tab + copy.

03

Submitted

With form.

04

vs disabled

Key diff.

05

.readOnly

JS property.

06

Boolean

true/false.

Purpose of readonly Attribute

Forms 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.

💡
Not a security boundary

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.

📝 Syntax

Add readonly as a boolean attribute on supported inputs or textarea:

readonly.html
<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>

Syntax Rules

  • Boolean attribute — presence means true: readonly or readonly="readonly".
  • Remove the attribute or set readOnly = false in JS to make the field editable again.
  • Valid on text-like input types and textarea.
  • Not valid on checkbox, radio, select, button, or file.
  • JavaScript property is readOnly (camelCase), not readonly.
  • Readonly fields are submitted; disabled fields are not.
  • Users can focus, select, and copy readonly content.

💎 Values

The readonly attribute is a boolean — it has no meaningful string values:

  • readonly — Field is read-only (most common).
  • readonly="readonly" — XHTML-style equivalent.
  • Attribute absent — Field is editable (default).
  • element.readOnly = true / false — JavaScript toggle.
readonly-boolean.html
<!-- Boolean presence -->
<input type="email" value="user@example.com" readonly>

<!-- JavaScript -->
<script>
  input.readOnly = true;   // lock
  input.readOnly = false;  // unlock
</script>

⚡ Quick Reference

Conceptreadonlydisabled
User can editNoNo
User can focusYesNo
Submitted with formYesNo
JS propertyreadOnlydisabled
Typical useDisplay-only valuesUnavailable controls
Valid ontext-like input, textareaMost form controls

Applicable Elements

Element / typeSupported?Notes
<input type="text">YesMost common
email, password, tel, url, searchYesText-entry types
number, date, time, datetime-localYesPicker inputs
<textarea>YesMulti-line text
checkbox, radio, fileNoUse disabled instead
<select>, <button>NoNot applicable

readonly vs disabled vs value

Featurereadonlydisabledvalue
Prevents editingYesYesNo
FocusableYesNoYes
Form submissionIncludedExcludedIncluded
PurposeLock UI editingDeactivate controlField content

Examples Gallery

Read-only form fields, toggling readOnly in JavaScript, and comparing submission behavior with disabled.

👀 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.

Example — Read-only form fields

Display account info users should see but not edit:

readonly-form.html
<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>
Try It Yourself

How It Works

All three fields are non-editable but remain in the tab order and submit their values when the form is posted.

Dynamic Values with JavaScript

Toggle read-only state when conditions change:

dynamic-readonly.html
<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>
Try It Yourself

How It Works

The IDL property is readOnly (camelCase). Set false or remove the attribute to unlock editing again.

Example — readonly vs disabled on submit

Readonly values submit; disabled values do not:

readonly-vs-disabled.html
<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>
Try It Yourself

How It Works

This is the most important practical difference. Use readonly when the server needs the value; use disabled when it should not be sent.

♿ Accessibility

  • Screen readers — Readonly fields are announced as read-only. Users can still navigate to them with Tab.
  • Visual distinction — Browsers may style readonly fields differently; add helper text if the locked state is not obvious.
  • Don’t use readonly for buttons — Use disabled on buttons and toggles instead.
  • Labels still required — Associate every readonly field with a <label>.
  • Explain why — Tell users why a field cannot be edited (e.g. “Contact support to change email”).

🧠 How readonly Works

1

Attribute set

readonly present.

Lock
2

No typing

Edit blocked.

UI
3

Focus OK

Tab + copy.

Access
=

Submitted

Value sent.

Browser Support

The readonly attribute on supported input types and textarea works in all modern browsers.

HTML Forms · Fully supported

Universal readonly support

Read-only fields work consistently across browsers on text-like inputs and textarea.

99% Browser support
Google Chrome Fully supported
Full support
Mozilla Firefox Fully supported
Full support
Apple Safari Fully supported
Full support
Microsoft Edge Fully supported
Full support
Internet Explorer IE 9+ supported
Full support
Opera Fully supported
Full support
readonly attribute 99% supported

Bottom line: Safe for read-only text fields and textareas in all modern browsers.

💡 Best Practices

✅ Do

  • Use readonly for display-only values that must submit
  • Pair with clear labels and helper text explaining why editing is locked
  • Use readOnly in JS when toggling based on user permissions
  • Validate all values on the server regardless of readonly
  • Prefer readonly over disabled when the value must reach the backend

❌ Don’t

  • Treat readonly as security — it is UI-only
  • Use readonly on checkbox, radio, or select (use disabled)
  • Confuse readonly with disabled submission rules
  • Forget that users can still copy readonly values
  • Use element.readonly in JS — the property is readOnly

Conclusion

The 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.

Key Takeaways

Knowledge Unlocked

Five truths every developer should know about readonly

Bookmark these before building forms.

5
Core concepts
02

Submitted

Unlike disabled.

Forms
03

Focusable

Tab + copy.

UX
04

.readOnly

camelCase JS.

API
05

Not security

Server validate.

Gotcha

❓ Frequently Asked Questions

It makes a field non-editable. Users can still focus, select, and copy the value, and the value is included when the form submits.
readonly blocks editing but keeps focus and submission. disabled blocks all interaction and excludes the value from the POST body.
Text-like input types and textarea. Not checkbox, radio, select, or button.
element.readOnly = true — note camelCase. Set false to unlock.
No. It only prevents casual UI editing. Always validate and authorize changes on the server.
Yes on supported input types and textarea in all modern browsers.

Lock form fields the right way

Practice readonly on profile forms, JavaScript toggles, and readonly-vs-disabled submission in the Try It editor.

Try readonly demo →

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.

5 people found this page helpful