Textarea

Struct Textarea 

Source
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 submission
  • rows: Visible number of text lines
  • cols: Visible width in average character widths
  • maxlength: Maximum number of characters
  • minlength: Minimum number of characters
  • placeholder: Hint text when empty
  • required: Makes the field mandatory
  • disabled: Disables the control
  • readonly: Makes the field read-only
  • autocomplete: Autocomplete behavior
  • wrap: Text wrapping behavior (“soft” or “hard”)
  • spellcheck: Enable spell checking
  • form: 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-describedby for additional instructions
  • Provide clear character limits when applicable
  • Ensure sufficient size for expected content
  • Consider resize behavior for user control
  • Use placeholder for hints, not instructions
  • Ensure adequate color contrast

§WHATWG Specification

Trait Implementations§

Source§

impl HtmlElement for Textarea

Source§

const TAG: &'static str = "textarea"

The HTML tag name (e.g., “div”, “span”, “img”).
Source§

const VOID: bool = false

Whether this is a void element (self-closing, no children allowed).
Source§

impl CanContain<Text> for Textarea

Source§

impl FlowContent for Textarea

Source§

impl InteractiveContent for Textarea

Source§

impl PalpableContent for Textarea

Source§

impl PhrasingContent for Textarea

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.