Learn HTML – Part 40 – textarea Tag – Multi-line Input
The HTML textarea tag is used to create a multi-line text input field in a form.
It allows users to enter longer pieces of text such as messages, comments, or descriptions.
What is the textarea Tag?
The textarea element defines a text input area that can contain multiple lines of text.
Unlike the input tag, which is used for single-line inputs, textarea is designed for larger text content.
Basic Syntax
<textarea></textarea>
Example – Simple Textarea
<form>
<label>Message:</label><br>
<textarea></textarea>
</form>
Output:
Using rows and cols Attributes
The size of the textarea can be controlled using the rows and cols attributes.
<textarea rows="4" cols="40"></textarea>
Example – Textarea with Size
<textarea rows="5" cols="40">
Enter your message here...
</textarea>
Output:
Common textarea Attributes
| Attribute | Description |
|---|---|
rows | Defines the visible number of text lines |
cols | Defines the width of the textarea |
placeholder | Displays hint text inside the textarea |
name | Specifies the textarea name |
required | Makes the field mandatory |
Example – Textarea with Placeholder
<textarea
rows="4"
cols="40"
placeholder="Enter your message">
</textarea>
Why Use textarea?
- Allows users to enter longer text
- Useful for messages or comments
- Commonly used in contact forms
- Improves form usability
The
textareatag is ideal for collecting longer text input from users.
Common Mistakes Beginners Make
- Using input instead of textarea for long text
- Not setting rows and cols properly
- Forgetting to include the name attribute
Conclusion
The HTML textarea tag is used to create multi-line text input fields.
It is commonly used in forms for messages, feedback, or comments.
What’s Next?
Now that you understand the textarea tag, the next step is learning about the select tag, which is used to create dropdown lists in HTML forms.
Next: Learn HTML – Part 41 – select Tag – Dropdown Lists →
Series: Learn HTML Series
