Textarea readOnly attribute

Definition and Usage

readOnly The attribute sets or returns whether the content of the text area should be read-only.

In a read-only text area, the content cannot be changed, but users can use the Tab key to switch to the area, or highlight and copy the content from it.

This property reflects the HTML readonly attribute.

Tip:If you want to prevent users from interacting with the text area, use disabled Property.

Example

Example 1

Set the text area to read-only:

document.getElementById("myTextarea").readOnly = true;

Try it yourself

Example 2

Determine if the text area is read-only:

var x = document.getElementById("myTextarea").readOnly;

Try it yourself

Syntax

Return the readOnly attribute:

textareaObject.readOnly

Set the readOnly attribute:

textareaObject.readOnly = true|false

Attribute Value

Value Description
true|false

Specifies whether the text area should be read-only

  • true - The text area is read-only
  • false - Default. The text area is variable

Technical Details

Return value: Boolean value, returns if the text area is read-only true; otherwise return false.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support