HTMLInputElement: readOnly property
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
ThereadOnly property of theHTMLInputElement interface indicates that the user cannot modify the value of the<input>. It reflects the<input> element'sreadonly boolean attribute; returningtrue if the attribute is present andfalse when omitted.
Unlike a form control with a truedisabled property, a truereadOnly property value does not prevent the user from clicking or selecting in the control.
While the HTMLreadonly attribute is ignored if the type ishidden,range,color,checkbox,radio,file,submit,reset,button, andimage, thereadOnly property istrue for these input types if the attribute is present,false otherwise.
In this article
Value
A boolean.
Examples
const inputElement = document.getElementById("total");console.log(inputElement.readOnly);inputElement.readOnly = true;Specifications
| Specification |
|---|
| HTML> # dom-input-readonly> |
Browser compatibility
See also
<input>HTMLInputElement.disabled:read-onlypseudo-class