Loading
The <textarea> element in HTML is used to create a multiline text input field inside a form. Unlike the regular <input> element ( which is typically one line), <textarea> allows users to enter longer messages, feedback or addresses.



When to Use <textarea> ?

  • Collecting feedback or comments
  • Taking in user addresses
  • Allowing for detailed input like descriptions, messages, or queries


Syntax:

<textarea rows="4" cols="30"></textarea>

AttributePurpose
rowsNumber of visible text lines
colsWidth of the text area ( in characters )



Example: Simple Textarea Form

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Textarea Example</title>
</head>

<body>
  <h2>Address Form</h2>

  <form>
    <label for="address">Enter your address:</label><br>
    <textarea id="address" name="address" rows="3" cols="30" placeholder="Type your full address here..."></textarea>
  </form>

</body>
</html>

Output:

Uploaded Image



Key Point

  • You can use the placeholder, name, id and other form related attributes just like <input>.
  • The content entered inside <textarea> is what gets submitted to the server.
  • It is resizeable by default in most browsers unless styled otherwise using CSS.