HTML5 Reference

HTML <textarea> tag

Definition

The <textarea> tag is used to define used to define a multiple line area for text input.

Use the <label> HTML tag to give the textarea control a description and to aid accessibility.

Example


<p><label for="pies">Who ate all the pies?</label></p>
<textarea id="pies" name="pies" rows="3" cols="30" placeholder="pie description.."></textarea>

Attributes

The following attributes can be used with the <textarea> tag.


<textarea> Specific Attributes
Attribute Value Description Example
autofocus empty string or autofocusGives focus to this text area on page load.

<textarea rows="3" cols="30" 
     autofocus></textarea>
<textarea rows="3" cols="30"
     autofocus="autofocus"></textarea>
colsnumberSpecifies the character width of the text area.

Default value is 20.

<textarea rows="3" cols="30"></textarea>
dirnameform idSpecifies the direction of the text entered in the input field.

Not supported in Firefoxx.

<textarea rows="3" cols="30" 
     dirname="someText"></textarea>
disabledempty string or disabledSpecifies this text area will be disabled until a certain condition occurs.

<textarea rows="3" cols="30" 
     disabled></textarea>
<textarea rows="3" cols="30" 
     disabled="disabled"></textarea>
formform idSpecifies the form that the text area belongs to

<textarea rows="3" cols="30" 
     form="someForm"></textarea>
maxlengthnumberSpecifies the maximum character length of the text area.

<textarea rows="3" cols="30" 
     maxlength="50"></textarea>
namenameSpecifies a name for the text area.

<textarea rows="3" cols="30" 
     name="name"></textarea>
placeholdernameSpecifies a reminder (word or phrase) to aid with data entry.

<textarea rows="3" cols="30" 
     placeholder="reminder"></textarea>
readonly empty string or readonlySpecifies that a text area is protected and not modifiable.

<textarea rows="3" cols="30" 
     readonly></textarea>
<textarea rows="3" cols="30" 
     readonly="readonly"></textarea>
required empty string or requiredSpecifies that a text area is required and needs to be populated.

<textarea rows="3" cols="30" 
     required></textarea>
<textarea rows="3" cols="30" 
     required="required"></textarea>
rowsnumberSpecifies the character height of the text area.

Default value is 2.

<textarea rows="3"  cols="30"></textarea>
wraphard or softSpecifies how the text area is wrapped on form submission.

<textarea rows="3" cols="30" 
     wrap="hard"></textarea>
<textarea> Global Attributes
Attribute Description Example
Common
classSpecifies a classname for the element allowing you to apply the style of the predefined class to the content.

<textarea class="name">
idSpecifies a unique id for the element allowing you to apply the style of the predefined id to the content.

<textarea id="name">
styleSpecifies an inline style for the element allowing you to apply the style to the contentt.

<textarea style="color:red;">
titleSpecifies an inline style for the element allowing you to apply the style to the content.

<textarea title="Content info">
Keyboard
accesskeySpecifies a keyboard shortcut to associate with the element.

<textarea accesskey="a">
tabindexSpecifies a tab order for the element.

<textarea tabindex="1">
Language
dirSpecifies the directional flow of the content.

<!-- The text will flow from left to right -->
<textarea dir="ltr">
<!-- The text will flow from right to left -->
<textarea dir="rtl">
langSpecifies a language code for the content of the element.

<textarea lang="en">
spellcheckSpecifies an inline style for the element allowing you to apply the style to the contentt.

<!-- Valid values true and false. -->
<!-- Default inherited/browser specific. -->
<textarea spellcheck="true"> 
translateSpecifies an inline style for the element allowing you to apply the style to the content.

<!-- Valid values yes and no. -->
<!-- Default yes. -->
<textarea translate="no"> 
Miscellaneous
contenteditableSpecifies whether the content of the element is editable.

<!-- Valid values true and false. -->
<!-- Default inherited. -->
<textarea contenteditable="true"> 
draggableSpecifies whether the element is draggable.

<!-- Valid values true and false. -->
<!-- Default browser specific. -->
<textarea draggable="true">
hiddenSpecifies whether the element is not yet, or no longer, relevant.

<!-- Valid values an empty string or hidden -->
<textarea hidden> 
<textarea hidden="hidden"> 
<textarea> Event Attributes
Attribute Description Example
Document Element
oncopyThe script to be run when the user copies the content of an element.

 <!-- Executes go() function -->
<textarea oncopy="go()"> 
oncutThe script to be run when the user cuts the content of an element.

 <!-- Executes go() function -->
<textarea oncut="go()">
onpasteThe script to be run when the user pastes some content into an element.

 <!-- Executes go() function -->
<textarea onpaste="go()">
Drag and Drop
ondragThe script to be run when an element is dragged.

 <!-- Executes go() function -->
<textarea ondrag="go()">
ondragendThe script to be run when an element has stopped being dragged.

 <!-- Executes go() function -->
<textarea ondragend="go()">
ondragenterThe script to be run when an element has been dragged to a valid drop target.

 <!-- Executes go() function -->
<textarea ondragenter="go()">
ondragleaveThe script to be run when an element leaves a valid drop target.

 <!-- Executes go() function -->
<textarea ondragleave="go()">
ondragoverThe script to be run when an element is being dragged over a valid drop target.

 <!-- Executes go() function -->
<textarea ondragover="go()">
ondragstartThe script to be run at the start of a drag operation.

 <!-- Executes go() function -->
<textarea ondragstart="go()">
ondropThe script to be run when a dragged element is being dropped.

 <!-- Executes go() function -->
<textarea ondrop="go()">
Form
onblurThe script to be run when the element loses focus.

 <!-- Executes go() function -->
<textarea onblur="go()">
onchangeThe script to be run when object changed and attempt to leave field.

 <!-- Executes go() function -->
<textarea onchange="go()">
oncontextmenuThe script to be run when a context menu is triggered.

 <!-- Executes go() function -->
<textarea oncontextmenu="go()">
onfocusThe script to be run when the element gets focus.

 <!-- Executes go() function -->
<textarea onfocus="go()">
oninputThe script to be run when an element gets user input.

 <!-- Executes go() function -->
<textarea oninput="go()">
oninvalidThe script to be run when an element is invalid.

 <!-- Executes go() function -->
<textarea oninvalid="go()">
onresetThe script to be run when a dragged element is being dropped.

 <!-- Executes go() function -->
<textarea onreset="go()">
onselectThe script to be run when some or all of the contents of an object are selected.

 <!-- Executes go() function -->
<textarea onselect="go()">
onsubmitThe script to be run when a form is submitted.

 <!-- Executes go() function -->
<textarea onsubmit="go()">
Keyboard
onkeydownThe script to be run when an element is in focus and keyboard key is pressed down.

 <!-- Executes go() function -->
<textarea onkeydown="go()">
onkeypressThe script to be run when an element is in focus and keyboard key is pressed down and released.

 <!-- Executes go() function -->
<textarea onkeypress="go()">
onkeyupThe script to be run when an element is in focus and keyboard key is released.

 <!-- Executes go() function -->
<textarea onkeyup="go()">
Media
onabortThe script code to be run on abort.

 <!-- Executes go() function -->
<textarea onabort="go()">
oncanplayThe script to be run when a file has buffered enough so it is ready to start playing.

 <!-- Executes go() function -->
<textarea oncanplay="go()">
oncanplaythroughThe script to be run when a file can be played all the way to the end without further need of buffering.

 <!-- Executes go() function -->
<textarea oncanplaythrough="go()">
oncuechangeThe script to be run when the cue changes when using the track element.

 <!-- Executes go() function -->
<textarea oncuechange="go()">
ondurationchangeThe script to be run when the length of the media is changed.

 <!-- Executes go() function -->
<textarea ondurationchange="go()">
onemptiedThe script to be run when a media resource element suddenly becomes empty, usually due to an error.

 <!-- Executes go() function -->
<textarea onemptied="go()">
onendedThe script to be run when the media has reach the end.

 <!-- Executes go() function -->
<textarea onended="go()">
onloadeddataThe script to be run when media data is loaded and playback can start.

 <!-- Executes go() function -->
<textarea onloadeddata="go()">
onloadedmetadataThe script to be run when metadata has been loaded.

 <!-- Executes go() function -->
<textarea onloadedmetadata="go()">
onloadstartThe script to be run whenthe media resource has started loading.

 <!-- Executes go() function -->
<textarea onloadstart="go()">
onpauseThe script to be run when the media resource has been paused.

 <!-- Executes go() function -->
<textarea onpause="go()">
onplayThe script to be run when the media resource starts playback.

 <!-- Executes go() function -->
<textarea onplay="go()">
onplayingThe script to be run when when playback has already begun.

 <!-- Executes go() function -->
<textarea onplaying="go()">
onprogressThe script to be run when the browser is fetching the media data.

 <!-- Executes go() function -->
<textarea onprogress="go()">
onratechangeThe script to be run when the playback rate changes.

 <!-- Executes go() function -->
<textarea onratechange="go()">
onseekedThe script to be run when the seeking attribute is set to false indicating that seeking has finished.

 <!-- Executes go() function -->
<textarea onseeked="go()">
onseekingThe script to be run when the seeking attribute is set to true indicating that seeking is currently active.

 <!-- Executes go() function -->
<textarea onseeking="go()">
onstalledThe script to be run when the browser is unable to continue fetching media data.

 <!-- Executes go() function -->
<textarea onstalled="go()">
onsuspendThe script to be run when media data has stopped before being completely loaded.

 <!-- Executes go() function -->
<textarea onsuspend="go()">
ontimeupdateThe script to be run when the media resources current playback position has changed.

 <!-- Executes go() function -->
<textarea ontimeupdate="go()">
onvolumechangeThe script to be run when the volume has changed or been muted.

 <!-- Executes go() function -->
<textarea onvolumechange="go()">
onwaitingThe script to be run when the media resource has paused but is expected to resume.

 <!-- Executes go() function -->
<textarea onwaiting="go()">
Mouse
onclickThe script to be run when when a mouse is clicked on an element.

 <!-- Executes go() function -->
<textarea onclick="go()">
ondblclickThe script to be run when a mouse is double clicked on an element.

 <!-- Executes go() function -->
<textarea ondblclick="go()">
onmousedownThe script to be run when he mouse button is pressed down while the cursor is over an element.

 <!-- Executes go() function -->
<textarea onmousedown="go()">
onmousemoveThe script to be run when the mouse button is moved.

 <!-- Executes go() function -->
<textarea onmousemove="go()">
onmouseoutThe script to be run when the mouse cursor moves off an element.

 <!-- Executes go() function -->
<textarea onmouseout="go()">>
onmouseoverThe script to be run when the mouse cursor moves over an element.

 <!-- Executes go() function -->
<textarea onmouseover="go()">
onmouseupThe script to be run when the mouse button is released while the cursor is over the element.

 <!-- Executes go() function -->
<textarea onmouseup="go()">
onwheelThe script to be run when the mouse wheel rolls up or down over an element.

 <!-- Executes go() function -->
<textarea onwheel="go()">
Scroll
onscrollThe script code to be run when the scrollbar of an element is being scrolled.

 <!-- Executes go() function -->
<textarea onscroll="go()"> 
Window - NONE

Relevant HTML Tutorials

HTML Lessons - Forms