<textarea>

  • Revision slug: HTML/HTML_Elements/textarea
  • Revision title: textarea
  • Revision id: 45000
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment update for bug 674558, clean up; 116 words added, 3 words removed

Revision Content

Summary

The textarea ({{ HTMLElement("textarea") }} HTML element represents a multi-line plain-text editing control.

Usage context

Content categories Flow content; phrasing content; interactive content; listed, labelable, submittable, resettable form-associated element.
Permitted content Character data
Tag omission None, must have both a start tag and an end tag.
Permitted parent elements Any element that accepts phrasing content
Normative document HTML 5, section 4.10.3; HTML 4.01, section 17.7

Attributes

Like all other HTML elements, this element supports the global attributes.

{{ htmlattrdef("autofocus") }} {{ HTMLVersionInline("5") }}
This Boolean attribute lets you specify that a form control should have input focus when the page loads, unless the user overrides it, for example by typing in a different control. Only one form-associated element in a document can have this attribute specified. 
{{ htmlattrdef("cols") }}
The visible width of the text control, in average character widths. If it is specified, it must be a positive integer. If it is not specified, the default value is 20 (HTML5).
{{ htmlattrdef("disabled") }}
This Boolean attribute indicates that the user cannot interact with the control. (If this attribute is not specified, the control inherits its setting from the containing element, for example {{ HTMLElement("fieldset") }}; if there is no containing element with the disabled attribute set, then the control is enabled {{ unimplemented_inline("557087") }}.)
{{ htmlattrdef("form") }} {{ HTMLVersionInline("5") }}
The form element that the textarea element is associated with (its "form owner"). The value of the attribute must be an ID of a form element in the same document. If this attribute is not specified, the textarea element must be a descendant of a form element. This attribute enables you to place textarea elements anywhere within a document, not just as descendants of their form elements.
{{ htmlattrdef("maxlength") }} {{ HTMLVersionInline("5") }}
The maximum number of characters (Unicode code points) that the user can enter. If it is not specified, the user can enter an unlimited number of characters.
{{ htmlattrdef("name") }}
The name of the control.
{{ htmlattrdef("placeholder") }} {{ HTMLVersionInline("5") }}
A hint to the user of what can be entered in the control. The placeholder text must not contain carriage returns or line-feeds.
{{ htmlattrdef("readonly") }}
This Boolean attribute indicates that the user cannot modify the value of the control. Unlike the disabled attribute, the readonly attribute does not prevent the user from clicking or selecting in the control. The value of a read-only control is still submitted with the form.
{{ htmlattrdef("required") }} {{ HTMLVersionInline("5") }}
This attribute specifies that the user must fill in a value before submitting a form.
{{ htmlattrdef("rows") }}
The number of visible text lines for the control.
{{ htmlattrdef("selectionDirection") }} {{ HTMLVersionInline("5") }}
The direction in which selection occurred. This is "forward" if the selection was made from left-to-right in an LTR locale or right-to-left in an RTL locale, or "backward" if the selection was made in the opposite direction. This can be "none" if the selection direction is unknown.
{{ htmlattrdef("selectionEnd") }}
The index to the last character in the current selection.
{{ htmlattrdef("selectionStart")) }}
The index to the first character in the current selection.
{{ htmlattrdef("wrap") }} {{ HTMLVersionInline("5") }}
Indicates how the control wraps text. Possible values are:
  • hard: The browser automatically inserts line breaks (CR+LF) so that each line has no more than the width of the control; the cols attribute must be specified.
  • soft: The browser ensures that all line breaks in the value consist of a CR+LF pair, but does not insert any additional line breaks.

If this attribute is not specified, soft is its default value.

DOM interface

This element implements the HTMLTextAreaElement interface.

{{ h1_gecko_minversion("Resizable textareas", "2.0") }}

{{ gecko("2.0") }} introduced support for resizable textareas. This is controlled by the {{ cssxref("resize") }} CSS property. Resizing of textareas is enabled by default, but you can explicitly disable it by including the following CSS:

textarea {
  resize: none;
}

Examples

<textarea name="textarea" rows="10" cols="50">Write something here</textarea>

Result

Compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{ CompatVersionUnknown() }} {{ CompatGeckoDesktop("1.0") }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }}
autofocus attribute {{ CompatVersionUnknown() }} {{ CompatGeckoMobile("2.0") }} {{ CompatNo() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }}
maxlength attribute {{ CompatVersionUnknown() }} {{ CompatGeckoMobile("2.0") }} {{ CompatNo() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }}
placeholder attribute {{ CompatVersionUnknown() }} {{ CompatGeckoMobile("2.0") }} {{ CompatNo() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }}
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{ CompatVersionUnknown() }} {{ CompatGeckoMobile("1.0") }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }}
autofocus attribute {{ CompatUnknown() }} {{ CompatGeckoMobile("2.0") }} {{ CompatNo() }} {{ CompatUnknown() }} {{ CompatUnknown() }}
maxlength attribute {{ CompatUnknown() }} {{ CompatGeckoMobile("2.0") }} {{ CompatNo() }} {{ CompatUnknown() }} {{ CompatUnknown() }}
placeholder attribute {{ CompatUnknown() }} {{ CompatGeckoMobile("2.0") }} {{ CompatNo() }} {{ CompatUnknown() }} {{ CompatUnknown() }}

Gecko notes

Starting in Gecko 6.0 {{ geckoRelease("6.0") }}, when a {{ HTMLElement("textarea") }} is focused, the insertion point is placed at the beginning of the text by default, instead of at the end. This change makes Gecko's behavior consistent with other popular browsers.

See also

Other form-related elements: {{ HTMLElement("form") }}, {{ HTMLElement("button") }}, {{ HTMLElement("datalist") }}, {{ HTMLElement("legend") }}, {{ HTMLElement("label") }}, {{ HTMLElement("select") }}, {{ HTMLElement("optgroup") }}, {{ HTMLElement("option") }}, {{ HTMLElement("input") }}, {{ HTMLElement("keygen") }}, {{ HTMLElement("fieldset") }}, {{ HTMLElement("output") }}, {{ HTMLElement("progress") }} and {{ HTMLElement("meter") }}.

{{ languages( { "fr": "fr/HTML/Element/textarea" } ) }}

Revision Source

<h2>Summary</h2>
<p>The <em>textarea</em> ({{ HTMLElement("textarea") }} HTML element represents a multi-line plain-text editing control.</p>
<h2>Usage context</h2>
<table class="standard-table"> <tbody> <tr> <td>Content categories</td> <td><a href="/en/HTML/Content_categories#Flow_content" title="en/HTML/Content categories#Flow content">Flow content</a>; <a href="/en/HTML/Content_categories#Phrasing_content" title="en/HTML/Content categories#Phrasing content">phrasing content</a>; <a href="/en/HTML/Content_categories#Interactive_content" title="en/HTML/Content categories#Interactive content">interactive content</a>; <a href="/en/HTML/Content_categories#form_listed" title="en/HTML/Content categories#form listed">listed</a>, <a href="/en/HTML/Content_categories#form_labelable" title="en/HTML/Content categories#form labelable">labelable</a>, <a href="/en/HTML/Content_categories#form_submittable" title="en/HTML/Content categories#form submittable">submittable</a>, <a href="/en/HTML/Content_categories#form_resettable" title="en/HTML/Content categories#form resettable">resettable</a> <a href="/en/HTML/Content_categories#Form-associated_content" title="en/HTML/Content categories#Form-associated content">form-associated</a> element.</td> </tr> <tr> <td>Permitted content</td> <td>Character data</td> </tr> <tr> <td>Tag omission</td> <td>None, must have both a start tag and an end tag.</td> </tr> <tr> <td>Permitted parent elements</td> <td>Any element that accepts <a href="/en/HTML/Content_categories#Phrasing_content" title="en/HTML/Content categories#Phrasing content">phrasing content</a></td> </tr> <tr> <td>Normative document</td> <td><a class=" external" href="http://www.w3.org/TR/html5/the-button-element.html#the-textarea-element" title="http://www.w3.org/TR/html5/the-button-element.html#the-textarea-element">HTML 5, section 4.10.3</a>; <a class=" external" href="http://www.w3.org/TR/html401/interact/forms.html#h-17.7" title="http://www.w3.org/TR/html401/interact/forms.html#h-17.7">HTML 4.01, section 17.7</a></td> </tr> </tbody>
</table>
<h2>Attributes</h2>
<p>Like all other HTML elements, this element supports the <a href="/en/HTML/Global_attributes" title="en/HTML/Global attributes">global attributes</a>.</p>
<dl> <dt>{{ htmlattrdef("autofocus") }} {{ HTMLVersionInline("5") }}</dt> <dd>This Boolean attribute lets you specify that a form control should have input focus when the page loads, unless the user overrides it, for example by typing in a different control. Only one form-associated element in a document can have this attribute specified. </dd> <dt>{{ htmlattrdef("cols") }}</dt> <dd>The visible width of the text control, in average character widths. If it is specified, it must be a positive integer. If it is not specified, the default value is <span style="font-family: Courier New;">20</span> (HTML5).</dd> <dt>{{ htmlattrdef("disabled") }}</dt> <dd>This Boolean attribute indicates that the user cannot interact with the control. (If this attribute is not specified, the control inherits its setting from the containing element, for example {{ HTMLElement("fieldset") }}; if there is no containing element with the <code>disabled</code> attribute set, then the control is enabled {{ unimplemented_inline("557087") }}.)</dd> <dt>{{ htmlattrdef("form") }} {{ HTMLVersionInline("5") }}</dt> <dd>The form element that the textarea element is associated with (its "form owner"). The value of the attribute must be an ID of a form element in the same document. If this attribute is not specified, the textarea element must be a descendant of a form element. This attribute enables you to place textarea elements anywhere within a document, not just as descendants of their form elements.</dd> <dt>{{ htmlattrdef("maxlength") }} {{ HTMLVersionInline("5") }}</dt> <dd>The maximum number of characters (Unicode code points) that the user can enter. If it is not specified, the user can enter an unlimited number of characters.</dd> <dt>{{ htmlattrdef("name") }}</dt> <dd>The name of the control.</dd> <dt>{{ htmlattrdef("placeholder") }} {{ HTMLVersionInline("5") }}</dt> <dd>A hint to the user of what can be entered in the control. The placeholder text must not contain carriage returns or line-feeds.</dd> <dt>{{ htmlattrdef("readonly") }}</dt> <dd>This Boolean attribute indicates that the user cannot modify the value of the control. Unlike the <code>disabled</code> attribute, the <code>readonly</code> attribute does not prevent the user from clicking or selecting in the control. The value of a read-only control is still submitted with the form.</dd> <dt>{{ htmlattrdef("required") }} {{ HTMLVersionInline("5") }}</dt> <dd>This attribute specifies that the user must fill in a value before submitting a form.</dd> <dt>{{ htmlattrdef("rows") }}</dt> <dd>The number of visible text lines for the control.</dd> <dt>{{ htmlattrdef("selectionDirection") }} {{ HTMLVersionInline("5") }}</dt> <dd>The direction in which selection occurred. This is "forward" if the selection was made from left-to-right in an LTR locale or right-to-left in an RTL locale, or "backward" if the selection was made in the opposite direction. This can be "none" if the selection direction is unknown.</dd> <dt>{{ htmlattrdef("selectionEnd") }}</dt> <dd>The index to the last character in the current selection.</dd> <dt>{{ htmlattrdef("selectionStart")) }}</dt> <dd>The index to the first character in the current selection.</dd> <dt>{{ htmlattrdef("wrap") }} {{ HTMLVersionInline("5") }}</dt> <dd>Indicates how the control wraps text. Possible values are: <ul> <li><span style="font-family: Courier New;">hard</span>: The browser automatically inserts line breaks (CR+LF) so that each line has no more than the width of the control; the <code>cols</code> attribute must be specified.</li> <li><span style="font-family: Courier New;">soft</span>: The browser ensures that all line breaks in the value consist of a CR+LF pair, but does not insert any additional line breaks.</li> </ul> <p>If this attribute is not specified, <span style="font-family: Courier New;">soft</span> is its default value.</p> </dd>
</dl>
<h2>DOM interface</h2>
<p>This element implements the <code><a href="/en/DOM/HTMLTextAreaElement" title="en/DOM/textarea">HTMLTextAreaElement</a></code> interface.</p>
<p>{{ h1_gecko_minversion("Resizable textareas", "2.0") }}</p>
<p>{{ gecko("2.0") }} introduced support for resizable textareas. This is controlled by the {{ cssxref("resize") }} CSS property. Resizing of textareas is enabled by default, but you can explicitly disable it by including the following CSS:</p>
<pre>textarea {
  resize: none;
}
</pre>
<h2>Examples</h2>
<pre class="brush: html">&lt;textarea name="textarea" rows="10" cols="50"&gt;Write something here&lt;/textarea&gt;
</pre>
<h4>Result</h4>
<p><textarea cols="50" name="textarea" rows="10">Write something here</textarea><img align="absmiddle" alt="" class="ife_marker" id="textarea_ife_marker_0" src="chrome://informenter/skin/marker.png" style="border: 0pt none; width: 14px; height: 19px; cursor: pointer; display: inline;" title="Max field length is unknown"></p>
<h2>Compatibility</h2>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop">
<table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Chrome</th> <th>Firefox (Gecko)</th> <th>Internet Explorer</th> <th>Opera</th> <th>Safari</th> </tr> <tr> <td>Basic support</td> <td>{{ CompatVersionUnknown() }}</td> <td>{{ CompatGeckoDesktop("1.0") }}</td> <td>{{ CompatVersionUnknown() }}</td> <td>{{ CompatVersionUnknown() }}</td> <td>{{ CompatVersionUnknown() }}</td> </tr> <tr> <td><code>autofocus</code> attribute</td> <td>{{ CompatVersionUnknown() }}</td> <td>{{ CompatGeckoMobile("2.0") }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatVersionUnknown() }}</td> <td>{{ CompatVersionUnknown() }}</td> </tr> <tr> <td><code>maxlength</code> attribute</td> <td>{{ CompatVersionUnknown() }}</td> <td>{{ CompatGeckoMobile("2.0") }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatVersionUnknown() }}</td> <td>{{ CompatVersionUnknown() }}</td> </tr> <tr> <td><code>placeholder</code> attribute</td> <td>{{ CompatVersionUnknown() }}</td> <td>{{ CompatGeckoMobile("2.0") }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatVersionUnknown() }}</td> <td>{{ CompatVersionUnknown() }}</td> </tr> </tbody>
</table>
</div>
<div id="compat-mobile">
<table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Android</th> <th>Firefox Mobile (Gecko)</th> <th>IE Mobile</th> <th>Opera Mobile</th> <th>Safari Mobile</th> </tr> <tr> <td>Basic support</td> <td>{{ CompatVersionUnknown() }}</td> <td>{{ CompatGeckoMobile("1.0") }}</td> <td>{{ CompatVersionUnknown() }}</td> <td>{{ CompatVersionUnknown() }}</td> <td>{{ CompatVersionUnknown() }}</td> </tr> <tr> <td><code>autofocus</code> attribute</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatGeckoMobile("2.0") }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> </tr> <tr> <td><code>maxlength</code> attribute</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatGeckoMobile("2.0") }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> </tr> <tr> <td><code>placeholder</code> attribute</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatGeckoMobile("2.0") }}</td> <td>{{ CompatNo() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> </tr> </tbody>
</table>
</div>
<h3>Gecko notes</h3>
<p>Starting in Gecko 6.0 {{ geckoRelease("6.0") }}, when a {{ HTMLElement("textarea") }} is focused, the insertion point is placed at the beginning of the text by default, instead of at the end. This change makes Gecko's behavior consistent with other popular browsers.</p>
<h2>See also</h2>
<p>Other form-related elements: {{ HTMLElement("form") }}, {{ HTMLElement("button") }}, {{ HTMLElement("datalist") }}, {{ HTMLElement("legend") }}, {{ HTMLElement("label") }}, {{ HTMLElement("select") }}, {{ HTMLElement("optgroup") }}, {{ HTMLElement("option") }}, {{ HTMLElement("input") }}, {{ HTMLElement("keygen") }}, {{ HTMLElement("fieldset") }}, {{ HTMLElement("output") }}, {{ HTMLElement("progress") }} and {{ HTMLElement("meter") }}.</p>
<p>{{ languages( { "fr": "fr/HTML/Element/textarea" } ) }}</p>
Revert to this revision