readonly: HTML attribute

The boolean readonly attribute, when present, makes the element immutable, meaning the user cannot modify the control.

If the readonly attribute is specified on an input element, because the user cannot modify the input, the element does not participate in constraint validation.

The readonly attribute is supported by the inputs <input type="text">, <input type="search">, <input type="url">, <input type="tel">, <input type="email" ">, <input type="password">, <input type="date">, <input type="month">, <input type="week">, <input type="time">, <input type="datetime-local"> <input type="number"> and the <textarea> elements. If present on any of these input types and elements, the pseudo class ::read-only will match. If the attribute is not included, the pseudo class :read-write will match.

The attribute is not supported, it is not relevant for <select> or for input types that are not already editable, such as checkbox and radio, or that cannot, by definition, start with a value, such as file input type . range and color , since both have default values. It is also not supported on hidden as a user cannot be expected to fill out a hidden form. Nor is it supported on any of the button types, including image.

When an input has the readonly attribute, the :read-only pseudo-class also applies to it. In contrast, inputs that support the readonly attribute but do not have the attribute set correspond to the :read-write pseudo-class.

Attribute interactions

The difference between disabled and readonly is that read-only controls can still function and are still focusable, while disabled controls cannot receive focus and are not submitted with the form and generally do not function as controls until they are enabled.

Because a read-only field cannot have its value changed by user interaction, required has no effect on inputs with the readonly attribute also specified.

The only way to dynamically change the value of the readonly attribute is through a script.

Constraint validation

If the item is read-only, the item's value cannot be updated by the user and does not participate in constraint validation.