References

Beginner-friendly references for web development, with live, editable examples.

The HTML readonly attribute

Attribute All modern browsers Updated
Quick answer

The HTML readonly attribute makes the value uneditable while the control remains focusable and is still submitted. It is used on the <input> and <textarea> elements.

Overview

The readonly attribute makes the value uneditable while the control remains focusable and is still submitted. It applies to the <input> and <textarea> elements.

Unlike disabled, a readonly field can still be focused and copied, and its value is submitted with the form.

Syntax

<input value="Fixed" readonly>

Values

Value
A boolean attribute — present or absent.

Example

Live example
<input value="Read-only value" readonly style="padding:8px;width:100%;">

Best practices

  • Give every control a <label> so it has an accessible name.
  • Treat client-side constraints as a convenience — always validate again on the server, since they can be bypassed.
  • Choose the most specific input type so users get the right on-screen keyboard and built-in checks.
  • Keep the submitted name and value meaningful for whatever processes the form.

Frequently asked questions

What does the readonly attribute do?
Makes a field read-only.
Are HTML form attributes enough for validation?
They give instant feedback, but client-side checks can be bypassed, so always validate on the server too.
Do form controls still need a label?
Yes. Every control needs a <label> for an accessible name, whatever attributes you set.
Which elements use the readonly attribute?
It is an element-specific attribute, used on form controls such as <input>, <select> and <textarea>.