HTML <textarea> Element
The <textarea> element creates a multiline text input control that allows users to enter longer amounts of text. It is commonly used for comments, messages, descriptions, feedback, and other form responses that may require more than one line.
Syntax
<label for="message">Message:</label>
<textarea id="message" name="message" rows="5" cols="40"></textarea>
Attributes
The <textarea> element supports the global HTML attributes and the following element-specific attributes:
| Attribute | Description |
|---|---|
autocomplete |
Indicates whether and how the browser may automatically complete the textarea value. |
cols |
Specifies the visible width of the text control in average character widths. Its value must be a positive integer. |
dirname |
Specifies a field name used to submit the text direction of the textarea value. |
disabled |
Prevents the user from interacting with the control and prevents its value from being submitted with the form. |
form |
Associates the textarea with a <form> element by its id, even when the textarea is not nested inside that form. |
maxlength |
Specifies the maximum number of characters the user is allowed to enter. |
minlength |
Specifies the minimum number of characters required when the textarea is subject to form validation. |
name |
Specifies the name used to identify the textarea's value when the form is submitted. |
placeholder |
Provides a short hint describing the type of information expected in the textarea. |
readonly |
Prevents the user from changing the value while allowing the control to remain focusable and its value to be submitted. |
required |
Specifies that the user must provide a value before the form can be submitted successfully. |
rows |
Specifies the number of visible text lines displayed by the control. Its value must be a positive integer. |
wrap |
Controls how text wrapping is handled when the textarea value is submitted. Common values are soft and hard. |
Example
This example creates a labeled message field that allows the user to enter several lines of text.
Usage Notes
Unlike the <input> element, <textarea> uses an opening and closing tag. Any initial text placed between these tags becomes the control's initial value.
The rows and cols attributes provide an initial size for the control, while CSS can be used to control its dimensions as part of the page design.
When a <textarea> is used for submitted form data, include a name attribute so its value is included with the form submission.
Accessibility
Provide each <textarea> with a clear accessible label, preferably by associating it with a <label> element using matching for and id values. Placeholder text should provide supplemental guidance rather than serve as the only label because it can disappear when the user begins entering text.
Browser Support
Baseline: Widely available indicates a feature has been supported by core browsers for at least 30 months. At this stage, the feature is considered stable and safe for most websites to use without needing to worry about compatibility issues or fallbacks, as it is supported by the vast majority of users' devices and browser versions.
For detailed browser compatibility information, see Can I Use: HTML <textarea> Element .
Related Elements
The <textarea> element is commonly used with <form>, <label>, <input>, and <button> elements to create form interfaces.
Specifications
The <textarea> element is defined in the WHATWG HTML Living Standard .
