Textarea
A native textarea element that automatically works with Field.
View as MarkdownAnatomy
Import the component and use it as a single part:
import { Textarea } from '@base-ui-components/react/textarea';
<Textarea />
API reference
defaultValue
Union
—
defaultValue
Union
—
- Name
- Type
string | number | string[] | undefined
onValueChange
function
—
onValueChange
function
—
- Name
- Description
Callback fired when the
value
changes. Use when controlled.- Type
| (( value: string, eventDetails: Textarea.ChangeEventDetails, ) => void) | undefined
maxRows
number
—
maxRows
number
—
- Name
- Description
Limit automatic height resizing to this many rows.
- Type
number | undefined
minRows
number
—
minRows
number
—
- Name
- Description
Enable automatic height resizing by setting the minimum number of rows.
- Type
number | undefined
className
string | function
—
className
string | function
—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
string | ((state: Field.Root.State) => string)
render
ReactElement | function
—
render
ReactElement | function
—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElement
or a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Field.Root.State, ) => ReactElement)
data-disabled
Present when the textarea is disabled.
data-valid
Present when the textarea is in valid state.
data-invalid
Present when the textarea is in invalid state.
data-dirty
Present when the textarea's value has changed.
data-touched
Present when the textarea has been touched.
data-filled
Present when the textarea is filled.
data-focused
Present when the textarea is focused.
Examples
Infinite resize
Setting only a minRows
will make the textarea automatically resize to fit its content.
Max rows
Setting both minRows
and maxRows
will make the textarea automatically resize between those limits.
Form integration
The textarea works seamlessly with the Form component and supports libraries like Zod for schema validation.
Field sizing
The CSS field-sizing
property lets form fields size themselves to their content. For example, a <textarea>
can grow or shrink as you type without JavaScript.
Browser support is about 71 % globally. Chrome 123+, Edge 123+, and Opera 109+ support it. Safari only recently added it in TP, and many others (Firefox, IE, Opera Mini, UC Browser, KaiOS) don’t yet.
Because support is incomplete, the demo may not work in older browsers or Safari <26
. If the textarea doesn’t resize, try a current Chrome or Edge build.
Once support passes ~90 %, we plan to switch the Textarea component to
field-sizing
by default, dropping the JS fallback.