What is the <textarea> tag in HTML?

The <textarea> tag in HTML

The <textarea> tag defines a multi-line text box to input data from the user. The structure of the <textarea> tag is as follows:

<textarea id="aboutMe" name="aboutMe" rows="2" cols="5">
I am a content writer at Educative, Inc.
</textarea>

The <textarea> tag displays a multi-line text box for data input. The height and width of the text box are usually defined by rows and cols attributes, respectively. The row attribute specifies the number of text lines that must be visible in the text box. The cols attribute specifies the number of characters that must be visible in a single line - the default value is 20. Both of these dimensions can also be set using CSS. Even if the rows and cols attributes are specified, the user can expand the text box by dragging the symbol in the bottom left corner. The name field is usually supplied when the data of the text box is to be submitted as part of a <form>.

Example usage of the <textarea> tag

The following code provides an example:

In the example above, the cols attribute for the <textarea> tag is set to 25; therefore, the visible characters in the first line are I am a content writer at . The rows attribute is set to 2, so there are only 2 visible rows in the text box.

Attributes

Attribute Value Description
autofocus autofocus If set, the text area is automatically focused when the page loads.
cols number Specifies the number of characters that must be visible in a single line.
dirname textareaname.dir
disabled disabled If set, the text area is disabled.
form form_id Links the text with the specified form.
maxlength number Restricts the number of characters that can be input in the text area.
name text Sets the name for the text area.
placeholder text The text is shown as a hint in the text area when there is no text data in it.
readonly readonly If set, the text area is read-only.
required required If set, the text area becomes a required field of the form.
rows number Specifies the number of visible lines of the text area.
wrap hard
soft
Specifies the wrapping of the text area when it is to be submitted in a form.
Copyright ©2024 Educative, Inc. All rights reserved