CSS :read-only Pseudo-Class

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

Definition and Usage

The :read-only pseudo-class matches elements the user cannot edit. On text fields that usually means the HTML readonly attribute. It is the complement of :read-write — equivalent to :not(:read-write).

Common use: style confirmation fields (name, address) so they look like fixed text while still submitting with the form.

Baseline — widely available.

Supported across modern browsers (MDN: widely available since July 2020). Prefer scoped selectors such as input:read-only — a bare :read-only also matches many non-form elements.

CSS Syntax

syntax.css
:read-only { /* styles */ }

Example: input:read-only { background: #e2e8f0; }.

What It Matches

:read-only has no values — it is a state. Typical matches:

TargetNotesTry it
input:read-onlyText-like inputs with readonlyTry it
textarea:read-onlyNon-editable multi-line fieldsTry it
With :read-writeContrast editable vs locked fieldsTry it
vs :disabledRead-only still focuses and submitsTry it
Non-form elementsAlso match (not editable) — scope your selectorCaution

How to Use :read-only

Mark the field in HTML, then style the state in CSS.

  1. Add readonly to the input or textarea (and keep a meaningful value).
  2. Select with input:read-only or textarea:read-only — not a bare * unless you intend to.
  3. Tone down borders and backgrounds so the field feels fixed, not broken.
  4. Pair with :read-write when the same form has editable fields too.
PieceRequired?Role
readonly attributeFor form fieldsMakes text controls non-editable but submittable
:read-only ruleYesVisual treatment for locked fields
Scoped selectorRecommendedAvoid styling every non-editable node on the page
:read-writeOptionalHighlight fields that are still editable

Live Preview

Toggle readonly on the sample input. The muted style applies only while it matches :read-only.

Rule shown: input:read-only

Field

Matches :read-only — muted background

CSS Examples

Short patterns for locked form fields. Use Try It Yourself for a live editor.

Example 1 — Read-Only Input

Mute a confirmation email field.

CSS
<style>
  input:read-only {
    background: #e2e8f0;
    border: 1px solid #cbd5e1;
    color: #334155;
  }
</style>

<label>
  Email
  <input type="email" value="[email protected]" readonly>
</label>
Try It Yourself

How It Works

  1. HTML readonly locks the field without disabling it.
  2. input:read-only matches that locked state.
  3. Muted styles signal “view only” while keeping focus possible.
  4. Value still submits with the form — unlike disabled.

Example 2 — Read-Only Textarea

Show a fixed address block for review.

CSS
<style>
  textarea:read-only {
    background: #f1f5f9;
    border: 0;
    resize: none;
  }
</style>

<label>
  Address
  <textarea readonly>23 Elastic Way
Bright Ridge, CA</textarea>
</label>
Try It Yourself

How It Works

  1. textarea + readonly locks multi-line text.
  2. textarea:read-only styles only locked areas.
  3. Remove border / resize so it reads more like static text.
  4. Good for checkout review before final submit.

Example 3 — Pair with :read-write

Contrast locked and editable fields in one form.

CSS
<style>
  input:read-only {
    background: #e2e8f0;
  }
  textarea:read-write {
    outline: 1px dashed #dc2626;
  }
</style>

<input type="text" value="Mr Soft" readonly>
<textarea>Add instructions</textarea>
Try It Yourself

How It Works

  1. Locked input matches :read-only → muted fill.
  2. Editable textarea matches :read-write → dashed outline.
  3. Users see which fields they can still change.
  4. Same pattern as MDN’s shipping-details review form.

Edge Cases & Pitfalls

Scope carefully — :read-only is broader than “has readonly=”.

scope

Matches more than form fields

Buttons, selects, and normal paragraphs are not :read-write, so they match :read-only. Prefer input:read-only / textarea:read-only.

vs disabled

Not the same as :disabled

Read-only can be focused and is submitted. Disabled is skipped on submit. Use :disabled when the control must be fully inactive.

a11y

Keep labels and contrast

Muted styles still need readable contrast. Pair with a clear label so users know the value is intentional, not broken.

contenteditable

Works beyond forms

A plain <p> matches :read-only; contenteditable content matches :read-write. Useful for rich-text demos — unexpected if you style globally.

Browser Support

:read-only is a browser CSS pseudo-class. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

:read-only

Widely available across modern browsers (MDN notes broad support from mid-2020). Pair with :read-write for form UX. Internet Explorer had incomplete / prefixed support historically.

97% Widely available
Google Chrome Supported
Full support
Mozilla Firefox Supported
Full support
Apple Safari Supported
Full support
Microsoft Edge Supported
Full support
Opera Supported
Full support
Samsung Internet Supported
Full support
Internet Explorer Partial
Legacy / incomplete
:read-only Baseline · Widely available

Bottom line: Safe for modern form styling. Scope to input/textarea. This is not a JavaScript runtime API.

Key Takeaways

  • Role: style elements the user cannot edit (often readonly fields).
  • vs disabled: read-only still focuses and submits.
  • Start simple: input:read-only { background: …; }.
  • Scope selectors — bare :read-only hits many non-form nodes.

One line: :read-only paints locked (but submittable) fields — mute them, don’t confuse them with disabled.

Frequently Asked Questions

It matches elements the user cannot edit. For inputs and textareas that usually means the HTML readonly attribute. It also matches anything that is not :read-write.
A read-only control can still be focused and its value is submitted with the form. A disabled control is not editable, is skipped on submit, and often looks fully inactive.
Yes. Elements where the readonly attribute has no effect (buttons, most non-form content) are also matched, because they are not :read-write. Scope your selector (e.g. input:read-only) when you only want form fields.
Often yes. Style confirmation fields with :read-only and editable fields with :read-write for a clear contrast in the same form.
No. It is a browser CSS pseudo-class. Node.js, Deno, and Bun do not apply it.

Next: :read-write

Learn how to style elements the user can edit.

:read-write 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.

5 people found this page helpful