- Home
- /
- Tutorials
- /
- HTML Tutorial
- /
- HTML <textarea> Tag
HTML Tags
HTML <textarea> Tag
The textarea tag is a text box for several lines: messages, comments, addresses, feedback. Unlike input, it has a closing tag, and any text between the tags is the starting content, not a placeholder.
That detail trips people up: even a space or a line break between <textarea> and </textarea> becomes part of the value. Keep the tags right next to each other when the box should start empty.
Syntax
html
<textarea name="message" rows="4" cols="50" placeholder="Enter your message here" required></textarea>| Attribute | What it does |
|---|---|
| name | The name the value is sent under. Without it, nothing is sent. |
| rows | The visible height, in lines of text. |
| cols | The visible width, in characters. CSS width is usually better. |
| placeholder | A hint shown while the box is empty. |
| maxlength / minlength | The longest and shortest allowed text. |
| required | The form cannot be sent while it is empty. |
| readonly / disabled | Can be read but not changed / greyed out and not sent. |
Example
html
<!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>Feedback Form</h2>
<form action="/samples/form_processor.php" method="post">
<label for="feedback">Your Feedback:</label><br>
<textarea id="feedback" name="feedback" rows="5" cols="50" placeholder="Enter your feedback here" required></textarea><br><br>
<input type="submit" value="Submit Feedback">
</form>
</body>
</html>A five-line box appears with a grey hint. The form refuses to send while it is empty, because of required.
Resizing
Most browsers add a handle at the bottom right so users can resize the box. Control it with CSS:
Let users make it taller, not wider
css
textarea {
width: 100%;
min-height: 8rem;
resize: vertical;
}Avoid resize: none unless the box grows by itself; otherwise long messages get hidden. Newer browsers support field-sizing: content, which makes the box grow as the user types.
Browser Support
Chrome | Edge | Firefox | Safari | Opera | IE9+ |
|---|---|---|---|---|---|
| Yes | Yes | Yes | Yes | Yes | Yes |
Good to know
- Always give it a
<label>, like every form field. - Line breaks typed by the user are kept in the value, so a server can store them as they are.
HTML <textarea> Tag exercises
Add a message box
Add a field for long text, named message, that is 4 lines high.
Result
