The HTML <textarea> element is a versatile form control that allows users to input multiple lines of text. It's commonly used for comments, reviews, or any situation where longer text input is required.
Here's the simplest form of a textarea:
<textarea></textarea>
A more complete example with attributes:
<textarea name="comment" id="userComment" rows="4" cols="50" placeholder="Enter your comment here..."></textarea>
Textareas can be styled using CSS to match your website's design. Here's a simple example:
textarea {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
resize: vertical;
}
name attribute for form submissionplaceholder text to guide usersmaxlength attributeTo improve accessibility:
<label> element to describe the textareaaria-describedby for additional instructionsTo further enhance your forms, explore these related HTML concepts:
The <textarea> element is supported in all modern browsers, making it a reliable choice for multi-line text input in web forms.
The HTML textarea is a fundamental component for collecting longer text input from users. By understanding its attributes and best practices, you can create effective and user-friendly forms for your web projects.