HTML DOM Textarea required Property

HTMLDOMWeb DevelopmentFront End Technology

The HTML DOM Textarea required property returns and modify the value of the required attribute of a text area in an HTML document.


Following is the syntax −

1. Returning required


2. Modifying required

object.required = true | false

Let us see an example of HTML DOM Textarea required Property:


Live Demo

<!DOCTYPE html>
<title>DOM Textarea required Property</title>
   body {
      text-align: center;
   .btn {
      display: block;
      margin: 1rem auto;
      background-color: #db133a;
      color: #fff;
      border: 1px solid #db133a;
      padding: 0.5rem;
      border-radius: 50px;
      width: 20%;
   .show-message {
      font-weight: bold;
      font-size: 1.4rem;
      color: #ffc107;
<h1>DOM Textarea required Property Demo</h1>
<form id="form" method="post" action="">
<legend>Form </legend>
<textarea rows="5" cols="20" required placeholder="Enter a message"></textarea>
<input type="submit" class="btn" value="Submit Form" onclick="checkRequired()">
<div class="show-message"></div>
   function checkRequired() {
      var textarea = document.querySelector("textarea");
      if (textarea.value === "") {
         document.querySelector(".show-message").innerHTML = "Please enter a message!";


Click on “Submit Form” button without entering any message in textarea element.

Updated on 16-Feb-2021 05:28:26