pub struct Textarea;Expand description
The <textarea> element - represents a multi-line plain text editing control.
§Purpose
The <textarea> element provides a multi-line text input control for entering larger
amounts of text. Unlike single-line <input> elements, textareas can contain multiple
lines and typically show scroll bars when content exceeds the visible area. Essential
for comments, descriptions, and longer form fields.
§Content Categories
- Flow Content
- Phrasing Content
- Interactive Content
- Palpable Content
§Permitted Content Model
- Text content (no child elements)
§Common Use Cases
- Comment and feedback forms
- Message composition areas
- Description and bio fields
- Code or text snippet input
- Notes and memo fields
§Key Attributes
name: Name for form submissionrows: Visible number of text linescols: Visible width in average character widthsmaxlength: Maximum number of charactersminlength: Minimum number of charactersplaceholder: Hint text when emptyrequired: Makes the field mandatorydisabled: Disables the controlreadonly: Makes the field read-onlyautocomplete: Autocomplete behaviorwrap: Text wrapping behavior (“soft” or “hard”)spellcheck: Enable spell checkingform: Associates with a form by ID
§Example
<!-- Basic textarea -->
<label for="message">Message:</label>
<textarea id="message" name="message" rows="4" cols="50"></textarea>
<!-- Textarea with placeholder -->
<label for="comment">Comment:</label>
<textarea id="comment" name="comment" rows="5"
placeholder="Enter your comment here..."></textarea>
<!-- Textarea with default value -->
<label for="bio">Biography:</label>
<textarea id="bio" name="bio" rows="6" cols="60">
This is the default text that appears in the textarea.
It can span multiple lines.
</textarea>
<!-- Textarea with character limits -->
<label for="tweet">Tweet (280 characters max):</label>
<textarea id="tweet" name="tweet" rows="3" maxlength="280" required></textarea>
<!-- Readonly textarea -->
<label for="terms">Terms and Conditions:</label>
<textarea id="terms" rows="10" cols="80" readonly>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
These terms cannot be edited.
</textarea>
<!-- Textarea with hard wrap -->
<label for="email-body">Email body:</label>
<textarea id="email-body" name="body" rows="10" cols="72" wrap="hard"></textarea>
<!-- Disabled textarea -->
<label for="status">Status:</label>
<textarea id="status" rows="2" disabled>Processing...</textarea>
<!-- Textarea with spell check disabled -->
<label for="code">Code snippet:</label>
<textarea id="code" name="code" rows="8" spellcheck="false"
style="font-family: monospace;"></textarea>§Accessibility
- Always provide an associated
<label> - Use
aria-describedbyfor additional instructions - Provide clear character limits when applicable
- Ensure sufficient size for expected content
- Consider resize behavior for user control
- Use
placeholderfor hints, not instructions - Ensure adequate color contrast
§WHATWG Specification
Trait Implementations§
Source§impl HtmlElement for Textarea
impl HtmlElement for Textarea
impl CanContain<Text> for Textarea
impl FlowContent for Textarea
impl InteractiveContent for Textarea
impl PalpableContent for Textarea
impl PhrasingContent for Textarea
Auto Trait Implementations§
impl Freeze for Textarea
impl RefUnwindSafe for Textarea
impl Send for Textarea
impl Sync for Textarea
impl Unpin for Textarea
impl UnwindSafe for Textarea
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more