HTML textarea element

Reference for the HTML textarea element: element content versus the value IDL, cols versus maxlength, and readonly compared with disabled.

标签页正文目前为英文。

The textarea element is a form control for multi-line text. This page deepens the catalog card for <textarea>. It complements the input page, which covers single-line and specialized types, and it does not rewrite that type list.

Both start and end tags are required. Permitted content is text. There is no value content attribute for the default text: the initial raw value is the element's text content. The value IDL property then reflects the current value after editing. The HTML parser also strips one leading newline that immediately follows the start tag; authors often put the text on the next line for that reason. This page does not treat html.parser's text nodes as a substitute for that raw-value algorithm.

Examples are complete local forms with no third-party action. They were checked with Python 3.13's html.parser as a structural tree, and with the site build. The forms are not submitted, and this is not a browser or accessibility test.

Official sources: MDN <textarea> element and the WHATWG HTML Living Standard. Fragments were checked with Python 3.13 html.parser. That parser builds an element tree; it is not a WHATWG conformance checker, and this is not a browser or accessibility test.

HTML tag catalog → · HTML tutorial overview →

Content versus value

Write the default text as children of textarea, not as a value attribute. A placeholder is only a hint when the value is empty; it is not a label and is not submitted. A name is required for the control to be submitted.

The first example sets visible size with rows and cols, and a separate maxlength on the value. Associate a label with for and id.

Default text is element content, and cols is not maxlength

<textarea name rows cols maxlength>
  default text
</textarea>

The initial text lives inside the element. cols sizes the visible width; maxlength limits the value length.

AttributeDescription
nameThe field name used in form submission.
rowsVisible height in text rows. The default is 2. It is not a maximum number of characters or lines in the value.
colsVisible width in average character widths. The default is 20. It is not a substitute for maxlength.
maxlengthMaximum length of the value, in UTF-16 code units as specified for the constraint. It does not change the visible cols width.
minlengthMinimum length of the value when the user has entered something. Unused in this example.
placeholderA hint shown when the value is empty. It is not a label and is not submitted.
wrapsoft is the default and does not insert line breaks into the submitted value. hard can insert line breaks in the submitted value and requires cols. Submission was not tested here.
  • No value attribute is present. The default wording is element content. Nothing is submitted from this page.
html
<form>
  <label for="bio">Short bio</label>
  <textarea id="bio" name="bio" rows="4" cols="40" maxlength="200" placeholder="One or two sentences">Default text lives in the element, not in a value attribute.</textarea>
</form>

What this markup means

The textarea has no value attribute. Its default text is the character data inside the element. cols="40" only suggests a visible width of about forty characters, while maxlength="200" is a separate limit on the value. placeholder would appear only if that content were cleared. The form has no remote action.

Related: Tag catalog: <textarea>, <form>, <input>, <label>

MDN documentation → · WHATWG HTML Standard →

readonly and disabled

readonly keeps the control focusable and, when it is otherwise successful, includes its value in the submission set. The user is not meant to edit it. disabled removes the control from the submission set and is not ordinarily activatable or focusable.

textarea has no type attribute like input does. Do not use a disabled textarea when you still need the text to be submitted; use readonly for that case. The distinction matches the input page, which already covers readonly versus disabled for input.

readonly remains submittable; disabled does not

<textarea name readonly>
<textarea name disabled>

readonly leaves the value in the successful set. disabled excludes the control from submission.

AttributeDescription
readonlyA boolean. The value cannot be edited, but the control can still be a successful, named field.
disabledA boolean. The control is not successful and is not submitted.
  • This contrast is structural. Focus, editing, and submission were not executed in a user agent.
html
<form>
  <label for="terms">Terms snapshot</label>
  <textarea id="terms" name="terms" rows="3" cols="40" readonly>These terms are prefilled and remain part of the submission set.</textarea>
  <label for="staff">Staff notes</label>
  <textarea id="staff" name="staff" rows="3" cols="40" disabled>Disabled text is not a successful control.</textarea>
</form>

What this markup means

The terms snapshot is readonly, so its text would still be submitted as terms if this form were submitted. The staff notes control is disabled, so it would be omitted even though it has a name and text content. Neither field is submitted from this page.

Related: Tag catalog: <textarea>, <input> readonly and disabled, <form>

MDN documentation → · WHATWG HTML Standard →