Definition
The <textarea> element is a multi-line field used in HTML Forms enabling the user input data.
Example
<label for="message">Leave a message</label>
<textarea id="message"
name="message"
rows="6"
placeholder="Feel free to leave a message and we
will get back to you as soon as we can."></textarea>Usage
- Both the opening and closing tags are required.
- The
<textarea>tag can be used anywhere that accepts phrasing content. - Only text may be placed in a
<textarea>element.
Attributes
The <textarea> element supports the Global Attributes, along with the following:
autocompleteThe
autocompleteattribute is a hint for the form’s autofill feature.autofocusThe
autofocusattribute is a boolean that determines whether a<textarea>element should automatically get focus when the page loads.colsThe
colsattribute specifies the maximum number of characters per line.dirnameThe
dirnameattribute enables the submission of the field text’s direction. It takes the value of thenameattribute of the input field followed by “.dir” as the value.disabledThe
disabledattribute is a boolean that determines whether the <textarea> element is disabled.formThe
formattribute specifies the form the<textarea>control belongs to. This allows you to associate it to<form>elements anywhere in the document, not just to the child elements of the<form>.maxlengthThe
maxlengthattribute specifies the maximum number of characters allowed. If this is not set, then the number of characters is unlimited.<label for="message">Leave a message</label> <textarea id="message" name="message" rows="6" cols="60" minlength="10" maxlength="25" ></textarea>minlengthThe
minlengthattribute specifies the minimum number of characters allowed. The minimum length does not prevent a user from removing characters, and technically it is still considered a valid submission unless you also use therequiredattribute.See the example above for
maxlength.nameThe
nameattribute specifies the name of the<textarea>element.placeholderThe
placeholderattribute specifies an expected value that will display in the<textarea>field. When a user starts typing the placeholder will dissappear.<label for="message">Leave a message</label> <textarea id="message" name="message" rows="6" cols="60" placeholder="Notice how this text dissappears when you start typing" ></textarea>readonlyThe
readonlyattribute is a boolean that specifies that the<textarea>element is read-only.<label for="message">Leave a message</label> <textarea id="message" name="message" rows="6" cols="60" placeholder="This text area is read only." readonly ></textarea>requiredThe
requiredattribute is a boolean that determines whether a value must be entered into the text area before form submission.rowsThe
rowsattribute specifies the number of visible lines in the control.wrapThe
wrapattribute specifies how the text is to be wrapped when submitted.It takes the values:
soft- The browser will automatically insert line breaks so that each line is not wider than the width of the control. This is the default value.hard- The browser will not automatically insert line breaks. Must be used with thecolsattribute.
Best Practices
- You can group long lists of items using the
<optgroup>tag.
Specification
Browser Support
Desktop
| Chrome | Edge | Firefox | IE | Opera | Safari |
|---|---|---|---|---|---|
| Yes | Yes | Yes | Yes | Yes | Yes |
Mobile
| Android Webview | Chrome Android | Firefox Android | Opera Android | iOS Safari | Samsung Internet |
|---|---|---|---|---|---|
| Yes | Yes | Yes | Yes | Yes | Yes |
