Description

The HTML element <textarea> is used to define a multi-line text input control, which can hold an unlimited number of characters.

It is commonly used to accept input from users that extends to multiple lines, like comments, feedback, reviews, etc.,

The text within this element is rendered by browsers in a mon-spaced or fixed-width font, usually Courier font.

The below table summarizes its usage.

Usage Details
Placement It is displayed as an Inline element.
Contents It can contain text.
Tags Both the opening and closing tags are required.
Versions HTML 2, 3.2, 4, 4.01, 5

Syntax

Here is the basic syntax of the <textarea> element.

<textarea rows="number" cols="number">...</textarea>

Examples

Run this on IDE

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Example - HTML Element textarea</title>
</head>
<body>
    <h2>HTML Textarea</h2>
    <form>
        <p>Please leave your comments here:<br>
            <textarea cols="50" rows="5">write something here....</textarea>
        </p>
    </form>
</body>
</html>

Attributes

The following table shows the list of supported and unsupported attributes for the <textarea> element.

Attribute Type Details
Element-Specific Attributes The tag <textarea> has some element-specific attributes listed in the below table.
Global Attributes Like all other HTML tags, the tag <textarea> supports the HTML Global Attributes.
Event Attributes The tag <textarea> also supports the HTML Event Attributes.

Here is a list of attributes that are specific to the <textarea> element.

Attribute Value Required Description
autofocus autofocus No Specifies that the textarea should automatically get focused when the document is loaded.
cols number No Specifies the number of visible text lines.
disabled disabled No This boolean attribute disables the textarea for user input or interaction.
form form-id No Specifies the form that the textarea is associated with i.e. its "form owner".
maxlength number No Specifies the maximum number of characters that the user can enter in the textarea.
minlength number No Specifies the minimum number of characters required that the user should enter in the textarea.
name unique-name No Assign a name to the textarea control.
placeholder text No Provides a hint to the user about what can be entered in the textarea. The placeholder text must not contain line breaks.
readonly readonly No This boolean attribute indicates that the user cannot modify the value of the textarea control (i.e. read-only).
required required No This Boolean attribute specifies that the user must fill in a value before submitting the form.
rows number No Specifies the visible width in average character widths.
wrap hard, soft No Specifies how the value of the textarea is to be wrapped for form submission.

Browser Compatibility

The tag <textarea> is supported in all modern browsers.

  • Google Chrome 1+
  • Internet Explorer or Edge 2+
  • Firefox 1+
  • Apple Safari 1+
  • Opera 4+

Related Links