Codectionary / Developer documentation / HTML

<textarea>

The <textarea> element creates a multi-line plain-text input control, ideal for comments, messages, and any content longer than a single line. Unlike <input>, its default value is placed between the opening and closing tags rather than in a value attribute, and users can typically resize it by dragging its corner.

Syntax

<textarea name="message" rows="4" cols="50">Default text</textarea>

Examples

Basic Textarea

A simple multi-line text field.

<label for="msg">Message:</label>
<textarea id="msg" name="message" rows="5" placeholder="Type your message here..."></textarea>

Textarea with Character Limit

Restricting input length with maxlength.

<textarea name="bio" maxlength="200" rows="4" placeholder="Tell us about yourself (200 characters max)"></textarea>

Non-resizable Styled Textarea

Preventing resizing and applying custom styles.

<textarea rows="6" style="width: 100%; resize: none; padding: 10px; border-radius: 8px; border: 1px solid #d1d5db; font-family: inherit;" placeholder="Write a review..."></textarea>

Attributes

  • rows (number): The visible number of text lines
  • cols (number): The visible width in average character widths
  • maxlength (number): The maximum number of characters allowed
  • placeholder (string): Hint text shown when empty
  • required (boolean): Marks the field as mandatory

Best practices

  • Set sensible default rows so the field looks appropriately sized before the user starts typing
  • Use the CSS resize property to control whether users can resize the textarea, rather than removing the ability entirely
  • Pair with a <label>, same as any other form field
  • Consider maxlength with a visible character counter for fields like bios or reviews

At a glance

Purpose
Structure and meaning for web content
File extension
.html · .htm
Runs in
Web browsers
Usually used with
CSS and JavaScript

Specifications & further reading

Related HTML documentation