Courses / HTML
1. Textarea Element
The <textarea> element is used for multi-line text input.
How It Works
Think of the `<textarea>` as a blank canvas where users can freely express their thoughts, similar to a notepad that expands as they write more.
The `<textarea>` tag creates a multiline input area.
The `rows` attribute defines the visible number of text lines.
The `cols` attribute sets the width of the text area in characters.
The content inside `<textarea>` is the default text shown when the page loads.
See It
This code creates a `<textarea>` with 4 visible lines and a width that can fit 50 characters. The default text "Enter your text here..." will be displayed when the page loads. Try changing the `rows` attribute to see how it affects the height.
<textarea rows="4" cols="50">Enter your text here...</textarea>Use It
A feedback form on a website where users can leave comments.
<form>
<label for="feedback">Feedback:</label>
<textarea id="feedback" rows="5" cols="40"></textarea>
<input type="submit" value="Submit">
</form>Using a `<textarea>` allows users to provide detailed feedback comfortably, enhancing their experience.
Break It
What will this display on the webpage?
<textarea rows="2" cols="10">This is a short text.</textarea>The `<textarea>` only displays the number of rows specified, so even though the text exceeds two lines, only the first two lines are visible, and the rest can only be accessed by scrolling.
Increase the `rows` attribute to allow more lines to be visible.
<textarea rows="4" cols="10">This is a short text.</textarea>Level Up
Placeholder Text: Using the `placeholder` attribute provides guidance on what to enter without occupying space in the text area.
Resizable Textarea: Adding the `style` attribute with `resize: both;` allows users to manually resize the textarea for better usability.
Prove It
Create a `<textarea>` for user comments with 6 visible rows and a placeholder text.
HTML
Textarea Element
The `<textarea>` element allows users to input multi-line text.
"I need a way for users to write longer messages without feeling cramped."
The `<textarea>` element is an HTML tag that creates a resizable box for users to enter text over multiple lines, making it ideal for comments or descriptions.
"I need a way for users to write longer messages without feeling cramped."
The `<textarea>` element is an HTML tag that creates a resizable box for users to enter text over multiple lines, making it ideal for comments or descriptions.