HTML DOM Textarea name Property

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


Following is the syntax −

1. Returning name

2. Adding name = “text”

Let us see an example of HTML DOM Textarea name 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;
   .show {
      font-size: 1.5rem;
      margin: 1rem 0;
<h1>DOM Textarea name Property Demo</h1>
<textarea rows="5" cols='20' name="I'm name attribute of textarea element">
Hi! I'm a textarea element with some dummy text.
<button onclick="set()" class="btn">Show Name Attribute Value</button>
<div class='show'></div>
   function set() {
      document.querySelector('.show').innerHTML = document.querySelector("textarea").name;


Click on “Show Name Attribute Value” button to display the value of name attribute of the textarea element.

Updated on: 20-Sep-2019


Kickstart Your Career

Get certified by completing the course

Get Started