HTML <textarea> Tag

Definition and Usage

<textarea> The tag defines a multi-line text input control.

<textarea> Elements are commonly used in forms to collect user input, such as comments or reviews.

The text area can accommodate an unlimited number of characters, and text is presented in a monospaced font (usually Courier).

The size of the textarea is specified by the cols and rows attributes (or using CSS).

The name attribute is required after submitting the form to reference form data (if the name attribute is omitted, the data of the textarea will not be submitted).

The id attribute is required to associate the textarea with the label (label).

Tip:Always add <label> Tag, for best accessibility practices!

See also:

HTML DOM Reference Manual:Textarea Object

CSS Tutorial:Set form styles

Example

Example 1

A multi-line text input control (textarea):

<label for="w3review">Comment on CodeW3C.com:</label>
<textarea id="w3review" name="w3review" rows="4" cols="50">
At codew3c.com, you will learn how to develop websites. They provide free tutorials on all Web development technologies.
</textarea>

Try it yourself!

Example 2

Disable default resize options:

<html>
<head>
<style>
textarea {
  resize: none;
}
</style>
</head>
<body>
<label for="w3review">Comment on CodeW3C.com:</label>
<textarea id="w3review" name="w3review" rows="4" cols="50">
At codew3c.com, you will learn how to develop websites. They provide free tutorials on all Web development technologies.
</textarea>
</body>
</html>

Try it yourself!

Attribute

Attribute Value Description
autofocus autofocus Specifies that the textarea should automatically receive focus when the page is loaded.
cols Number Specifies the visible width of the textarea.
dirname textareaname.dir Specifies the text direction of the text in the submitted textarea.
disabled disabled Specifies that the textarea should be disabled.
form Form id Specifies the form that the textarea belongs to.
maxlength Number Specifies the maximum number of characters allowed in the textarea.
name Text Specifies the name of the textarea.
placeholder Text Specifies a brief hint that describes the expected value of the text area.
readonly readonly Specifies that the textarea should be read-only.
required required Specifies that the textarea is required.
rows Number Specifies the number of visible lines in the textarea.
wrap
  • hard
  • soft
Specifies how the text in the textarea should be wrapped when the form is submitted.

Global Attributes

<textarea> The tag also supports Global Attributes in HTML.

Event Attributes

<textarea> The tag also supports Event Attributes in HTML.

Default CSS Settings

No.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support