---
title: TextArea
description: TextArea
element: vaadin-text-area
---

## Description

`<vaadin-text-area>` is a web component for multi-line text input.

```html
<vaadin-text-area label="Comment"></vaadin-text-area>
```

### Prefixes and suffixes

These are child elements of a `<vaadin-text-area>` that are displayed
inline with the input, before or after.
In order for an element to be considered as a prefix, it must have the slot
attribute set to `prefix` (and similarly for `suffix`).

```html
<vaadin-text-area label="Description">
  <div slot="prefix">Details:</div>
  <div slot="suffix">The end!</div>
</vaadin-text-area>
```

### Styling

The following custom properties are available for styling:

Custom property                | Description                | Default
-------------------------------|----------------------------|---------
`--vaadin-field-default-width` | Default width of the field | `12em`

The following shadow DOM parts are available for styling:

Part name            | Description
---------------------|----------------
`label`              | The label element
`input-field`        | The element that wraps prefix, value and suffix
`field-button`       | Set on the clear button
`clear-button`       | The clear button
`error-message`      | The error message element
`helper-text`        | The helper text element wrapper
`required-indicator` | The `required` state indicator element

The following state attributes are available for styling:

Attribute            | Description
---------------------|---------------------------------
`disabled`           | Set when the element is disabled
`has-value`          | Set when the element has a value
`has-label`          | Set when the element has a label
`has-helper`         | Set when the element has helper text or slot
`has-error-message`  | Set when the element has an error message
`has-tooltip`        | Set when the element has a slotted tooltip
`invalid`            | Set when the element is invalid
`input-prevented`    | Temporarily set when invalid input is prevented
`focused`            | Set when the element is focused
`focus-ring`         | Set when the element is keyboard focused
`readonly`           | Set when the element is readonly

Note, the `input-prevented` state attribute is only supported when `allowedCharPattern` is set.

See [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.

## Properties

### accessibleName

**Type:** `string | null | undefined`

String used to label the component to screen reader users.

### accessibleNameRef

**Type:** `string | null | undefined`

Id of the element used as label of the component to screen reader users.

### allowedCharPattern

**Type:** `string`

A pattern matched against individual characters the user inputs.

When set, the field will prevent:
- `keydown` events if the entered key doesn't match `/^allowedCharPattern$/`
- `paste` events if the pasted text doesn't match `/^allowedCharPattern*$/`
- `drop` events if the dropped text doesn't match `/^allowedCharPattern*$/`

For example, to allow entering only numbers and minus signs, use:
`allowedCharPattern = "[\\d-]"`

### autocapitalize

**Type:** `"characters" | "none" | "off" | "on" | "sentences" | "words"`

This is a property supported by Safari and Chrome that is used to control whether
autocapitalization should be enabled when the user is entering/editing the text.
Possible values are:
characters: Characters capitalization.
words: Words capitalization.
sentences: Sentences capitalization.
none: No capitalization.

### autocomplete

**Type:** `string | undefined`

Whether the value of the control can be automatically completed by the browser.
List of available options at:
https://developer.mozilla.org/en/docs/Web/HTML/Element/input#attr-autocomplete

### autocorrect

**Type:** `boolean`

This is a property supported by Safari that is used to control whether
autocorrection should be enabled when the user is entering/editing the text.
Possible values are:
on: Enable autocorrection.
off: Disable autocorrection.

### autofocus

**Type:** `boolean`

Specify that this control should have input focus when the page loads.

### autoselect

**Type:** `boolean`

If true, the input text gets fully selected when the field is focused using click or touch / tap.

### clearButtonVisible

**Type:** `boolean`

Set to true to display the clear icon which clears the input.

It is up to the component to choose where to place the clear icon:
in the Shadow DOM or in the light DOM. In any way, a reference to
the clear icon element should be provided via the `clearElement` getter.

### disabled

**Type:** `boolean`

If true, the user cannot interact with this element.

### errorMessage

**Type:** `string | null | undefined`

Error to show when the field is invalid.

### helperText

**Type:** `string | null | undefined`

String used for the helper text.

### invalid

**Type:** `boolean`

Set to true when the field is invalid.

### label

**Type:** `string | null | undefined`

The label text for the input node.
When no light dom defined via [slot=label], this value will be used.

### manualValidation

**Type:** `boolean`

Set to true to enable manual validation mode. This mode disables automatic
constraint validation, allowing you to control the validation process yourself.
You can still trigger constraint validation manually with the `validate()` method
or use `checkValidity()` to assess the component's validity without affecting
the invalid state. In manual validation mode, you can also manipulate
the `invalid` property directly through your application logic without conflicts
with the component's internal validation.

### maxlength

**Type:** `number | null | undefined`

Maximum number of characters (in Unicode code points) that the user can enter.

### maxRows

**Type:** `number | null | undefined`

Maximum number of rows to expand to before the text area starts scrolling. This effectively sets a max-height
on the `input-field` part. By default, it is not set, and the text area grows with the content without
constraints.

### minlength

**Type:** `number | null | undefined`

Minimum number of characters (in Unicode code points) that the user can enter.

### minRows

**Type:** `number`

Minimum number of rows to show. Default is two rows.

When using a custom slotted textarea, the minimum number of rows are not applied for backwards compatibility.

### name

**Type:** `string`

The name of this field.

### pattern

**Type:** `string`

A regular expression that the value is checked against.
The pattern must match the entire value, not just some subset.

### placeholder

**Type:** `string`

A hint to the user of what can be entered in the field.

### readonly

**Type:** `boolean`

When present, it specifies that the field is read-only.

### required

**Type:** `boolean`

Specifies that the user must fill in a value.

### title

**Type:** `string`

The text usually displayed in a tooltip popup when the mouse is over the field.

### value

**Type:** `string`

The value of the field.

## Methods

### checkValidity

**Type:** `(() => boolean) & (() => boolean)`

Returns true if the current textarea value satisfies all constraints (if any).

### clear

**Type:** `() => void`

Clear the value of the field.

### scrollToEnd

**Type:** `() => void`

Scrolls the textarea to the end if it has a vertical scrollbar.

### scrollToStart

**Type:** `() => void`

Scrolls the textarea to the start if it has a vertical scrollbar.

### validate

**Type:** `() => boolean`

Validates the field and sets the `invalid` property based on the result.

The method fires a `validated` event with the result of the validation.

## Events

### change

**Type:** [TextAreaChangeEvent](#textareachangeevent)

Fired when the user commits a value change.

### input

**Type:** `CustomEvent`

Fired when the value is changed by the user: on every typing keystroke,
and the value is cleared using the clear button.

### invalid-changed

**Type:** [TextAreaInvalidChangedEvent](#textareainvalidchangedevent)

Fired when the `invalid` property changes.

### validated

**Type:** [TextAreaValidatedEvent](#textareavalidatedevent)

Fired whenever the field is validated.

### value-changed

**Type:** [TextAreaValueChangedEvent](#textareavaluechangedevent)

Fired when the `value` property changes.

## Types

### TextAreaChangeEvent

```ts
/**
 * Fired when the user commits a value change.
 */
export type TextAreaChangeEvent = Event & {
  target: TextArea;
};
```

### TextAreaInvalidChangedEvent

```ts
/**
 * Fired when the `invalid` property changes.
 */
export type TextAreaInvalidChangedEvent = CustomEvent<{ value: boolean }>;
```

### TextAreaValidatedEvent

```ts
/**
 * Fired whenever the field is validated.
 */
export type TextAreaValidatedEvent = CustomEvent<{ valid: boolean }>;
```

### TextAreaValueChangedEvent

```ts
/**
 * Fired when the `value` property changes.
 */
export type TextAreaValueChangedEvent = CustomEvent<{ value: string }>;
```


