HTML Tags – Text Area Tag

What is the HTML <textarea> tag ?

HTML <textarea> tag is used for create multi-line text input.

HTML <textarea> element is often used in a form, to collect user inputs like comments or reviews.

HTML <textarea> size is specified by the <cols> and <rows> attributes.

HTML <textarea> size can also be defined through CSS height and width properties.

How HTML <textarea> tag works ?

HTML <textarea> element represents a multi-line plain-text editing control.

HTML <textarea> can hold an unlimited number of characters and the texts are displayed in a fixed-width font (usually courier).

By default browsers has render the <textarea> element texts in a monospace or fixed-width font.

name” attribute is needed to reference the form data after the form is submitted (if you omit the name attribute, no data from the text area will be submitted).

id” attribute is needed to associate the text area with a label.

Note : Always add the <label> tag for best accessibility practices!

Why is HTML <textarea> tag used ?

HTML <textarea> is mostly used inside the <form> tag.

HTML <textarea> is useful to allowing users to enter a sizeable amount of free-form text in Webpages.

For example a comment box on a review or feedback form.

HTML beginners tutorial !!!

Click to Learn More about – HTML Tutorial for beginners

Syntax :


Example :

<!DOCTYPE html>
        <title>textarea tag</title>
                h2 {
                        color: blue;
                        font-style: italic;

                body {
                        text-align: left;
        <h1>Welcome to CSTechbook</h1>
        <h2>HTML Textarea tag </h2>
        <form action="#">
		</textarea><br />
                <input type="submit">

Output :

<textarea> Tag Attributes

HTML <textarea> tag support following specific attributes.

1autofocusautofocusSpecifies that a <textarea> should be focus automatically when the page loads.
2colsnumberSpecifies the visible width of the <textarea> element.
3dirnametextareaname.dirSpecifies text direction of <textarea> element when will submitted the form.
4disableddisabledSpecifies that <textarea> element should be disabled.
5formform_idSpecifies one or more forms that associate with <textarea> element.
6maxlengthnumberSpecifies the maximum number of characters allowed in the <textarea> element.
7nametextSpecifies the name for <textarea> element.
8placeholdertextSpecifies short hint that describe to the user of what value should be enter in the <textarea> element.
9readonlyreadonlySpecifies that <textarea> element should be read-only, user can not modify it.
10requiredrequiredSpecifies that user is required to filled <textarea> field before submitting the form.
11rowsnumberSpecifies the number of visible lines in the <textarea> element.
Specifies how the text in the <textarea> should be wrap to the next line..

Global Attributes

HTML <textarea> tag support following global attributes.

1idunique_nameDeclared unique id for an element.
2classclass_nameDeclared one or more classnames for an element.
3stylestylesCSS inline styles specify an element.
4titletitleSpecify extra details of element contain, this will display as a “tooltip” for an elements.

Event Attributes

HTML <textarea> tag support following event attributes.

1onfocusscriptelement gets focus on object when script tobe run.
2onblurscriptelement lose the focus on object when scrip tobe run.
3onabortscriptelement gets aborted on object when script tobe run.
4onchangescriptelement gets anytime change on object when script tobe run.
5onbeforeunloadscriptelement gets unloaded on object when scrip tobe run.
6onclickscriptclicked on object when script tobe run.
7ondblclickscriptdouble click on object when script tobe run.
8onkeydownscriptkey is pressed when script tobe run.
9onkeypressscriptkey is pressed over element then released when script tobe run.
10onkeyupscriptkey is released over element when script tobe run.
11onmousedownscriptmouse button was pressed over an element when script tobe run.
12onmouseoutscriptmouse pointer release over an element when script tobe run.
13onmousemovescriptrun mouse pointer moved when script tobe run.
14onmouseoverscriptrun mouse pointer move over when script tobe run.
15onmouseupscriptmouse button is released when script tobe run.
16onresetscriptform has been reset when script tobe run.
17onselectscriptSelect some content when script tobe run.
18onsubmitscriptform has been submitted when script tobe run.
19onloadscriptobject has load when script tobe run.
20onchangescriptallow to change the object when script tobe run.
21onunloadscriptunload to the browser window when script tobe run.
22ondragscriptelement being dragged when script tobe run.
23ondragendscriptelement being stop dragged when script tobe run.
24ondragenterscriptelement being go target dragged when script tobe run.
25ondragleavescriptelement being leave to target dragged when script tobe run.
26ondragoverscriptelement being over to target dragged when script tobe run.
27ondragstartscriptelement being start dragged when script tobe run.
28ondropscriptelement being dropped when script tobe run.
29onerrorscriptelement error occurs when script tobe run.
30onmessagescriptelement message display when script tobe run.
31onerrorscriptelement error occurs when script tobe run.
32onmousewheelscriptmouse wheel will be rotate when script tobe run.
33onscrollscriptscrollbar is scroll when script tobe run.
34onresizescriptelement should be resize when script tobe run.
35onselectscriptall element content selected when script tobe run.
36onstoragescriptelement should be store in target when script tobe run.

Browser Compatibility

6Internet ExplorerYes