Skip to main content

What does <textarea> do and when should you use it?

The <textarea> element is used for multi-line text input: comments, reviews, messages, descriptions and any other data that does not fit into one short <input> field.

Unlike <input type="text">, which is meant for a single line, <textarea> lets the user write several lines of text and even use line breaks.


1. Basic usage example

html
<form action="/feedback" method="post"> <label for="message">Your review:</label><br> <textarea id="message" name="message" rows="4" cols="40" placeholder="Write here..."></textarea> <br> <button type="submit">Submit</button> </form>

Result: a large text field appears where you can write a multi-line message.


2. Main
AttributePurposeExample
nameField name (key for sending data)name="comment"
rowsNumber of visible rowsrows="5"
colsField width in characterscols="40"
placeholderHint inside the fieldplaceholder="Enter your message..."
maxlengthMaximum number of charactersmaxlength="500"
requiredMakes the field mandatoryrequired
readonlyRead-only (cannot be edited)readonly
disabledDisables the field (inactive)disabled
wrapControls line wrapping (soft or hard)wrap="soft"

3. Difference from

Criterion<input type="text"><textarea>
Number of linesOnly oneSeveral
Line breaksNoYes
SizeFixedCan be resized (dragged with the mouse)
PurposeShort data (name, email, login)Long text (comment, message, description)

Comparison example:

html
<input type="text" name="title" placeholder="Title"> <textarea name="description" placeholder="Description"></textarea>

The first is for a short title, the second is for a long description.


4. Default value

The text between the opening and closing <textarea> tag is treated as the initial value:

html
<textarea name="text">Default text</textarea>

5. How the data is sent

On form submission, the browser sends the content of <textarea> as the value tied to its name:

Example:

html
<textarea name="message">Hello!</textarea>

The server receives:

javascript
message=Hello!

6. When to use

Use it when you need to:

  • collect a lot of text (a review, comment, letter, description);
  • let the user enter line breaks;
  • collect free-form content, rather than something limited to short fields.

Summary:

PropertyValue
Tag<textarea> (paired)
PurposeMulti-line input field
Key attributesname, rows, cols, placeholder, maxlength
Difference from <input>Supports several lines and line breaks
Used forComments, messages, descriptions, feedback forms

In simple terms: <textarea> is a "notepad" inside the site, where a user can write out a longer text. If <input> is a field for a "name", then <textarea> is a field for a "thought".

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.