<textarea> Tag in HTML | Multiline Input Field
The <textarea> tag in HTML is used to create a multi-line text input field, allowing users to input large amounts of text. Unlike the <input type="text">
field, <textarea>
can span multiple lines, making it ideal for comments, feedback, or any extended text content.
Key Points on <textarea> Tag:
<textarea>
is a self-closing tag and requires both opening and closing tags (<textarea>...</textarea>
).- By default, it provides unlimited text length, but you can set limits using attributes like
maxlength
androws
andcols
for sizing. - Supports global attributes and events, allowing further customization and interactivity.
Syntax of <textarea> Tag:
Syntax Example
<textarea name="field_name" rows="5" cols="40">Default text</textarea>
Example of <textarea> Tag in HTML:
This example demonstrates the use of the <textarea>
tag with placeholder text and custom rows and columns.
Code Example
<form action="/submit_comment" method="post">
<label for="comment">Enter your comment:</label>
<textarea id="comment" name="comment" rows="4" cols="50" placeholder="Write your comment here..."></textarea>
</form>
Output
Attributes of <textarea> Tag:
- name: Specifies the name of the textarea field, used for form data submission.
- rows: Defines the visible number of lines in the textarea (height).
- cols: Sets the width of the textarea in character columns.
- maxlength: Limits the maximum number of characters allowed in the textarea.
- placeholder: Displays placeholder text when the textarea is empty.
- readonly: Makes the textarea read-only, so the user cannot modify its content.
- disabled: Disables the textarea, making it unselectable and non-submittable.
Advantages of Using <textarea> Tag:
- User-Friendly: Ideal for large text inputs, enhancing the user experience in form design.
- Customizable Size: Adjustable dimensions with
rows
andcols
, suitable for various screen sizes. - Interactive Attributes: Supports various attributes and events, allowing extensive customization.
The <textarea>
tag is essential for creating multi-line input fields in HTML forms, making it a versatile and interactive element for users to submit long-form text content.