ReferenceStandard

The textarea element: multiline plain text

Textarea provides a multiline plain-text editing control.

Intermediate3 min readLearn · Practice · Review

Published by HTML Code Runner · AI-assisted material · Independent editorial review pending · Editorial policy

On this page

Purpose and content model

Textarea provides a multiline plain-text editing control. It is suitable for a message, comment, or other content where line breaks matter. It is not a rich-text editor: markup typed into the control is text, and the receiving application must decide how to store and safely display it.

Initial content is written between the start and end tags, unlike an input whose default value normally comes from a value attribute. The live value property can differ after editing. A closing textarea tag must be escaped correctly when it is part of a code sample placed inside another textarea.

Syntax and working example

<label for="message">Your message</label>
<textarea id="message" name="message" rows="6" minlength="20" maxlength="2000" aria-describedby="message-help" required></textarea>
<p id="message-help">Include the date and location of the workshop.</p>

Supported attributes and behavior

Name supplies the submission key. Rows and cols describe an initial preferred size; CSS can make the field responsive. Minlength, maxlength, required, readonly, disabled, placeholder, autocomplete, form, dirname, and wrap apply in their supported ways. Wrap=hard can affect submitted line breaks and requires an appropriate column count; soft preserves the usual distinction between visual wrapping and explicit newlines. Readonly and disabled are not interchangeable.

Another practical pattern

<label for="notes">Reference notes</label>
<textarea id="notes" rows="4" readonly>Membership renewals open in November.</textarea>

Accessibility and browser notes

Provide a persistent visible label and enough space for the expected answer. Avoid disabling resizing without a strong usability reason. If a character counter is provided, do not announce every keystroke through an aggressive live region. Clearly distinguish a character limit from the information the user needs to provide.

Common mistakes

A value attribute does not supply textarea's initial text. Indentation inside the element can unintentionally become part of the initial value. Never display submitted textarea content through raw innerHTML without an appropriate sanitization strategy; plain-text display should use textContent or proper escaping.

Verify your implementation

Paste several paragraphs, edit in the middle, and test line breaks after submission and redisplay. Check maximum-length behavior with non-ASCII characters and your server's counting rules. Confirm readonly content remains readable and selectable if that is part of the workflow.

Standard status and sources

Standard; browser availability must be checked independently of specification status.

HTML specification · MDN reference and compatibility data