HTML tagForms

<textarea>

A multi-line text field for longer input: messages, reviews, descriptions.

Display
inline-block
Closing tag
Required
Permitted content
Text that becomes the field’s initial value
On this page

Example

#
HTML
<style>
  label { display: block; margin-bottom: 6px; }
  textarea { width: 100%; max-width: 420px; }
</style>
<label for="feedback">What can we improve in the course?</label>
<textarea id="feedback" name="feedback" rows="4" maxlength="500" placeholder="Write a few sentences…"></textarea>
Preview

Definition and usage

#

The <textarea> element creates a field where you can write many lines of text: a message in a contact form, a comment, a project description or a snippet of code. Unlike <input>, it has a closing tag, and you write the initial value between the tags rather than in a value attribute.

The text between the tags is taken literally, including whitespace. Indentation from your source code will end up in the field, so close </textarea> right after the content, with no extra spacing.

You set the size with the rows and cols attributes, or in CSS. By default, the user can resize the field by dragging its corner, controlled by the CSS resize property. Since 2026, in all major browsers the field can also grow with its content on its own thanks to field-sizing: content.

Syntax

#
Syntax
<textarea name="name" rows="4"></textarea>

Attributes

#
  • rows / cols

    number

    The field’s height in lines of text and its width in characters, 2 lines and 20 characters by default. This is only the initial size, which you can override in CSS.
  • placeholder

    text

    A hint visible in an empty field. Just like in <input>, it doesn’t replace a label.
  • minlength / maxlength

    number of characters

    The shortest and longest text length allowed. maxlength blocks further typing, and minlength is checked when the form is submitted.
  • required

    boolean attribute

    The field must be filled in before the form submits.
  • readonly / disabled

    boolean attribute

    readonly lets you read and copy the text, but not change it, and the value will be sent. disabled turns the field off completely and skips it when submitting.
  • wrap

    soft | hard

    Decides whether long lines wrapped in the field should be sent with extra newline characters. soft (the default) only wraps the text on screen, while hard inserts real newline characters on submit and requires cols to be given.

The element also supports all global attributes, such as class, id, style and hidden.

Attributes in practice

#

rows / cols

number

The field’s height in lines of text and its width in characters, 2 lines and 20 characters by default. This is only the initial size, which you can override in CSS.

HTML
<textarea rows="5" cols="36" aria-label="Notes">Lesson 3: forms
- a label connects to a field through for
- a button with no type submits the form</textarea>
Preview

placeholder

text

A hint visible in an empty field. Just like in <input>, it doesn’t replace a label.

HTML
<textarea rows="3" cols="36" aria-label="Project description" placeholder="What did you learn building this project?"></textarea>
Preview

minlength / maxlength

number of characters

The shortest and longest text length allowed. maxlength blocks further typing, and minlength is checked when the form is submitted.

HTML
<form>
  <textarea name="bio" rows="3" cols="36" minlength="20" maxlength="160" required aria-label="About me"></textarea>
  <p><button>Save bio</button></p>
</form>
Preview

required

boolean attribute

The field must be filled in before the form submits.

HTML
<form>
  <textarea name="question" rows="2" cols="36" required aria-label="Question for the mentor"></textarea>
  <p><button>Ask the question</button></p>
</form>
Preview

readonly / disabled

boolean attribute

readonly lets you read and copy the text, but not change it, and the value will be sent. disabled turns the field off completely and skips it when submitting.

HTML
<p><textarea rows="2" cols="36" readonly aria-label="Assignment text">Build a page with three sections and a menu.</textarea></p>
<p><textarea rows="2" cols="36" disabled aria-label="Mentor comment">The mentor hasn't graded the assignment yet.</textarea></p>
Preview

Browser support

#

Widely available

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • Don’t set the content with a value attribute, because <textarea> doesn’t have one. Write the initial value between the tags.
  • If the user should only be able to resize the field’s height, set resize: vertical in CSS.
  • For fields with a character limit, show a counter, for example "120/500", so the limit doesn’t catch the user off guard mid-sentence.

Related entries

#

Spotted a mistake or missing an example? Write to us.