Textarea
An unstyled multi-line text input component with auto-resize support.
Build fully custom multi-line text inputs with complete control over layout and styling.
basic-demo
Pre-styled Versions
Choose a pre-styled library to use Textarea with ready-made designs.
For hook-based usage without components, see the Headless API.
Features#
- Single component rendering a native
<textarea>element - Built-in auto-resize that adjusts height based on content using CSS
field-sizingwith JavaScript fallback - Native
<textarea>semantics with full HTML attribute support
Usage#
import { Textarea } from 'primereact/textarea';<Textarea rows={5} cols={30} />Behavior#
Polymorphic Rendering#
Use as to change the rendered HTML element or use a custom React component.
<Textarea as="div" contentEditable role="textbox" />Render Function Children#
Textarea accepts a render function as children, providing access to the component instance.
<Textarea>{(instance) => <span>Custom render</span>}</Textarea>Pass Through#
Some parts may not be visible in the preview depending on the component's current state.
/* Select a part to see its CSS selector for custom styling */API#
Textarea#
| Name | Type | Default |
|---|---|---|
ref | Ref<unknown> | — |
| The reference to the component instance. | ||
pIf | boolean | true |
| Whether the component should be rendered. | ||
style | CSSProperties | ((instance?: TextareaInstance) => CSSProperties) | — |
| The style to apply to the component. | ||
className | string | ((instance?: TextareaInstance) => string) | — |
| The class name to apply to the component. | ||
as | string | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode> | — |
| The component type to render. | ||
asChild | boolean | false |
| Whether the component should be rendered as a child component. | ||
instance | TextareaInstance | — |
| The instance to pass to the component. | ||
pt | SafeRecord<TextareaPassThrough> | — |
| The pass-through props to pass to the component. | ||
ptOptions | PassThroughOptions | — |
| The pass-through options to pass to the component. | ||
unstyled | boolean | — |
| Whether the component should be rendered without classes. | ||
dt | unknown | — |
| The design token to use for the component. | ||
styles | StylesOptions<ComponentInstance> | — |
| The styles to use for the component. | ||
render | (instance: TextareaInstance) => ReactNode | — |
| The render function to render the component with instance access. | ||
children | any | — |
| The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates. | ||
autoResize | boolean | false |
| When present, height of textarea changes as being typed. | ||
size | "small" | "large" | — |
| Defines the size of the Textarea. | ||
variant | "outlined" | "filled" | — |
| Specifies the input variant of the component. | ||
fluid | boolean | — |
| When enabled, the component will stretch to occupy the full width of its container. | ||
invalid | boolean | false |
| When present, it specifies that the component should have invalid state style. | ||
[key: string] | any | — |
pt-{optionName}-* | - | — |
| Pass through attributes for customizing component. For more info, see Pass Through tab. | ||
| Attribute | Value |
|---|---|
data-scope | "textarea" |
data-part | "root" |
data-invalid | Present when invalid |
Defines passthrough(pt) options of Textarea component.
| label | type | description |
|---|---|---|
| root | TextareaPassThroughType<TextareaHTMLAttributes<HTMLTextAreaElement>> | Used to pass attributes to the root's DOM element. |
Accessibility#
Screen Reader#
Textarea renders a native textarea element. Provide an accessible name with a visible label, aria-label, or aria-labelledby.
Keyboard Support#
Textarea uses native textarea keyboard behavior.