<textarea>

Term side of the Card.
Topic: Forms
Unit title: <textarea>
Categories: Tag
Explanation side of the Card

Explanation: The element that creates a multi-line text input field, allowing users to enter longer pieces of text. It's commonly used in forms where large amounts of input are required, like comments or feedback sections.

Browser compatibility:
  • The chrome browser supports this feature starting from version 1.
  • The edge browser supports this feature starting from version 12.
  • The firefox browser supports this feature starting from version 1.
  • The safari browser supports this feature starting from version 4.
Availability: 

Example

Wronghtml
<textarea name="bio" value="Hello">
</textarea>
Righthtml
<label for="bio">Bio</label>
<textarea id="bio" name="bio" rows="4">Hello</textarea>

A textarea's initial text goes between the tags, and whitespace inside is kept, so the closing tag stays on the same line.

Common mistakes

  • Setting a value attribute on <textarea>, which is ignored.
  • Indenting the closing tag, which adds spaces to the default text.

Key points

  • Default text goes between the tags, not in a value attribute.
  • The <textarea> has a linked <label> and a name.
  • Auto-growing uses CSS field-sizing: content where supported, with a JS fallback.

Interview questions

How do I stop users from resizing a textarea?

Use CSS resize: none, or resize: vertical to allow only height changes.

Does maxlength work on textarea?

Yes, maxlength limits how many characters users can type.

Analytics cookiesWe'd like to use analytics cookies to see which pages are useful. They're set only if you accept. Privacy Policy