> Markdown version of [Text Area](https://vaadin.com/docs/v23/components/text-area). Section index: [llms.txt](https://vaadin.com/docs/v23/components/llms.txt)

# Text Area

Text Area is an input field component for multi-line text input.

**TypeScript** — `text-area-basic.ts`

```html
<vaadin-text-area
  label="Comment"
  .maxlength="${this.charLimit}"
  .value="${this.text}"
  .helperText="${`${this.text.length}/${this.charLimit}`}"
  @value-changed="${(event: TextAreaValueChangedEvent) => {
    this.text = event.detail.value;
  }}"
></vaadin-text-area>
```

**Java** — `TextAreaBasic.java`

```java
TextArea textArea = new TextArea();
textArea.setLabel("Comment");
textArea.setMaxLength(charLimit);
textArea.setValueChangeMode(ValueChangeMode.EAGER);
textArea.addValueChangeListener(e -> {
    e.getSource()
            .setHelperText(e.getValue().length() + "/" + charLimit);
});
textArea.setValue("Great job. This is excellent!");
add(textArea);
```

Text Area is typically used for descriptions, comments, and other longer free-form content.

## <a id="common-input-field-features"></a>Common Input Field Features

Text Area includes all Text Field and shared input field features.

- [See Text Field features](https://vaadin.com/docs/v23/components/text-field.md)

- [See shared input field features](https://vaadin.com/docs/v23/components/input-fields.md)

## <a id="automatic-height-adjustment"></a>Automatic Height Adjustment

Unless set to a fixed height, Text Area adjusts its height automatically based on its content. The default and minimum height is two rows of text.

**TypeScript** — `text-area-auto-height.ts`

```html
<vaadin-text-area label="Description" value="${loremIpsum}"></vaadin-text-area>
```

**Java** — `TextAreaAutoHeight.java`

```java
TextArea textArea = new TextArea();
textArea.setWidthFull();
textArea.setLabel("Description");
textArea.setValue(loremIpsum);
add(textArea);
```

### <a id="minimum-and-maximum-height"></a>Minimum and Maximum Height

The automatic resizing can be restricted to a minimum and maximum height:

**TypeScript** — `text-area-height.ts`

```html
<style>
  vaadin-text-area {
    width: 100%;
    min-height: 100px;
    max-height: 150px;
  }
</style>

<vaadin-text-area label="Description" value="${loremIpsum}"></vaadin-text-area>
```

**Java** — `TextAreaHeight.java`

```java
TextArea textArea = new TextArea();
textArea.setWidthFull();
textArea.setMinHeight("100px");
textArea.setMaxHeight("150px");
textArea.setLabel("Description");
textArea.setValue(loremIpsum);
add(textArea);
```

## <a id="character-counter"></a>Character Counter

Longer free-form inputs are often capped at a certain character limit. The current character count and upper limit should be displayed to the user, for example by using the [Helper](https://vaadin.com/docs/v23/components/input-fields.md#helper) feature:

**TypeScript** — `text-area-helper.ts`

```html
private charLimit = 600;

@state()
private text = loremIpsum;

protected override render() {
  return html`
    <vaadin-text-area
      label="Description"
      .maxlength="${this.charLimit}"
      .value="${this.text}"
      .helperText="${`${this.text.length}/${this.charLimit}`}"
      @value-changed="${(event: TextAreaValueChangedEvent) => {
        this.text = event.detail.value;
      }}"
    ></vaadin-text-area>
  `;
}
```

**Java** — `TextAreaHelper.java`

```java
TextArea textArea = new TextArea();
textArea.setWidthFull();
textArea.setLabel("Description");
textArea.setMaxLength(charLimit);
textArea.setValueChangeMode(ValueChangeMode.EAGER);
textArea.addValueChangeListener(e -> {
    e.getSource()
            .setHelperText(e.getValue().length() + "/" + charLimit);
});
textArea.setValue(loremIpsum);
add(textArea);
```

## <a id="related-components"></a>Related Components

| Component                                                                      | Usage recommendations                               |
| ------------------------------------------------------------------------------ | --------------------------------------------------- |
| [Text Field](https://vaadin.com/docs/v23/components/text-field.md)             | Basic single-line text input.                       |
| [Rich Text Editor](https://vaadin.com/docs/v23/components/rich-text-editor.md) | Multi-line text entry with rich formatting support. |

`79CE0145-8514-417E-A033-6AB79E7BF86D`
