HTML - wrap Attribute



The wrap attribute of HTML is used to wrap the text in a text area when submitted in a HTML form. This attribute can be applied on the <textarea> element.

This attribute takes following values−

  • Soft − This is the default value. It specifies that the text in the textarea will not be wrapped when the form is submitted.
  • Hard − It defines that the text in a textarea wraps when the form is submitted.

Syntax

Following is the syntax of the wrap attribute −

<textarea wrap="soft|hard"> ...content </textarea>

Example

In the following example, we are using the wrap attribute with the value "hard" in the <textarea> tag.

<!DOCTYPE html>
<html>
<body>
   <h1>The textarea wrap attribute</h1>
   <form action="https://www.tutorialspoint.com/index.htm">
      <textarea rows="3" cols="20" name="usrtxt" wrap="hard">
         At tutorialspoint you will find free Web-building tutorials.
      </textarea>
      <br>
      <input type="submit">
   </form>
</body>
</html>

On running the above code, it will generate an output consisting of the textarea field along with a click button on the webpage.

Example

Considering the another scenario, where we are using the wrap attribute with value "soft" in the <textarea> tag.

<!DOCTYPE html>
<html>
<body>
   <h1>The textarea wrap attribute</h1>
   <form action="https://www.tutorialspoint.com/index.htm">
      <textarea rows="3" cols="20" name="usrtxt" wrap="soft">
         At tutorialspoint you will find free Web-building tutorials.
      </textarea>
      <br>
      <input type="submit">
   </form>
</body>
</html>

When we run the above code, it will generate an output consisting of the textarea field along with a click button displayed on the webpage.

Example

Let's look at the following example, where we are going to use the wrap attribute with the value "soft" Here, we have created two buttons: the first will submit the form, and the second will show the wrap value.

<!DOCTYPE html>
<html>
   <style>
   body {
      color: #000;
      height: 100vh;
   }

   .btn {
      background: #db133a;
      border: none;
      height: 2rem;
      border-radius: 2px;
      width: 40%;
      display: block;
      color: #fff;
      outline: none;
      cursor: pointer;
      margin: 1rem 0;
   }

   .show {
      font-size: 1.5rem;
      margin: 1rem 0;
   }
   </style>
<body>
   <h1>HTML wrap Attribute Demo</h1>
   <form action='' method="post">
      <textarea rows="3" cols="28" wrap="soft">Hi! I'm a text area element with some dummy text.</textarea>
      <input type="submit" class='btn' value="Submit Form">
   </form>
   <button onclick="set()" class="btn">Show wrap value</button>
   <div class="show"></div>
   <script>
      function set() {
         document.querySelector('.show').innerHTML = "The value of wrap attribute is " + document.querySelector("textarea").wrap;
      }
   </script>
</body>
</html>

On running the above code, the output window will pop up displaying the textarea field along with two buttons on the webpage.

html_attributes_reference.htm
Advertisements