HTML DOM Textarea readOnly Property

The HTML DOM Textarea readOnly property returns and modify whether the content of a text area element in an HTML document should be read only or not.


Following is the syntax −

1. Returning readOnly


2. Adding readOnly

object.readOnly = true | false

Let us see an example of HTML DOM Textarea readOnly Property −


<!DOCTYPE html>
   body {
      color: #000;
      background: lightseagreen;
      height: 100vh;
   .btn {
      background: #db133a;
      border: none;
      height: 2rem;
      border-radius: 2px;
      width: 40%;
      display: block;
      color: #fff;
      outline: none;
      cursor: pointer;
<h1>DOM Textarea readOnly Property Demo</h1>
<textarea rows="5" cols='20' name="I'm name attribute of textarea element">
Hi! I'm a text area element with some dummy text.
<button onclick="set()" class="btn">Toggle Read Only</button>
   function set() {
      var ta = document.querySelector("textarea");
      if (ta.readOnly === true) {
         ta.readOnly = false;
      } else {
         ta.readOnly = true;


Click on “Toggle Read Only” button to toggle the value of readOnly attribute of the textarea element.