The <textarea> element
The <textarea> tag creates a multi-line text box, used for comments, messages and other longer answers. Its size is set with rows and cols or with CSS, and maxlength limits how much can be typed. Unlike <input>, any starting text goes between the opening and closing tags, not in a value attribute.
Last updated: October 3, 2026
Quick facts
| Category | Flow content, phrasing content, interactive content, form-associated (listed, labelable, submittable, resettable) |
| Content model | Text only (no elements) |
| Tag omission | Neither the start nor the end tag can be omitted |
| Permitted parents | Any element that accepts phrasing content (usually inside a <form>) |
| DOM interface | HTMLTextAreaElement |
Syntax
Live example
Edit the code below and watch the preview update instantly.
Attributes
| Attribute | Description |
|---|---|
| name | The name sent with the text when the form is submitted |
| rows / cols | The visible height in lines and width in characters |
| placeholder | A hint shown while the box is empty |
| maxlength / minlength | The most and fewest characters allowed |
| required | The box must be filled in before the form can be sent |
| readonly | The text can be read and copied but not changed |
| disabled | The box is turned off and not submitted |
| wrap | soft (default) or hard, which keeps line breaks at the box width when submitted (needs cols) |
Common examples
Get and clear the text with JavaScript
A textarea’s text is in its .value property, both for reading and changing it.
A label with a helpful hint
Connect a hint to the field with aria-describedby so screen readers read it along with the label.
A full-width box on any screen
Make the textarea fill its container and include padding in the width, so it never overflows on phones.
<textarea> vs contenteditable
A <textarea> is a form field for plain text: it has no bold or links, its value is sent with the form automatically, and it works with labels, validation and every screen reader. Adding the contenteditable attribute to an element makes its HTML editable in place, which is how rich-text editors (bold, lists, links) are built.
For comments, messages and most forms, use a textarea — it’s simpler and safer. Reach for contenteditable only when people genuinely need formatting, and then you must collect the content with JavaScript and clean the HTML on the server before saving it.
| <textarea> | contenteditable | |
|---|---|---|
| Content | Plain text | Formatted HTML |
| Sent with forms | Automatically | Needs JavaScript |
| Best for | Messages, comments | Rich-text editors |
Common mistakes to avoid
- Using a
valueattribute. It does nothing on a textarea; put the default text between the tags. - Accidental spaces in the default text. Everything between
<textarea>and</textarea>is content, including line breaks and indentation, so keep the tags together when it should start empty. - No label. A placeholder like “Your message…” disappears as soon as someone types; add a real <label>.
- Fixed widths.
cols="80"overflows small screens; set the width in CSS instead.
Accessibility & SEO tips
- If you limit the length with
maxlength, show a visible character counter so people aren’t surprised when typing stops. - Allow vertical resizing (
resize: vertical) rather than turning resizing off completely — people with large fonts or long messages rely on it. - Keep
spellcheckon for normal writing, and turn it off withspellcheck="false"for code or usernames.
Browser support
Supported in every browser. Newer extras such as the CSS field-sizing property (auto-growing boxes) are only in some browsers, so treat them as a bonus.
Tutorials: How to make a contact form, HTML forms tutorial