Latest web development tutorials
 

Textarea readOnly Property

< Textarea Object

Example

Set a text area to be read-only:

document.getElementById("myTextarea").readOnly = true;
Try it Yourself »

Definition and Usage

The readOnly property sets or returns whether the contents of a text area should be read-only.

In a read-only text area, the content cannot be changed, but a user can tab to it, or highlight and copy the content from it.

This property reflects the HTML readonly attribute.

Tip: To prevent the user from interacting with the text area, use the disabled property instead.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The readOnly property is supported in all major browsers.


Syntax

Return the readOnly property:

textareaObject.readOnly

Set the readOnly property:

textareaObject.readOnly=true|false

Property Values

Value Description
true|false Specifies whether a text area should be read-only or not.
  • true - The text area is read-only
  • false - Default. The text area is changeable

Technical Details

Return Value: A Boolean, returns true if the text area is read-only, otherwise it returns false

More Examples

Example

Find out if a text area is read-only or not:

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

The result of x will be:

true
Try it Yourself »

< Textarea Object