InputText
An unstyled text input component with data attributes and native input semantics.
Build fully custom text inputs with complete control over layout and styling.
basic-demo
Pre-styled Versions
Choose a pre-styled library to use InputText with ready-made designs.
For hook-based usage without components, see the Headless API.
Features#
- Single component rendering a native
<input>withtype="text"default - Native
<input>semantics with full HTML attribute support
Usage#
import { InputText } from 'primereact/inputtext';<InputText placeholder="Enter text" />Behavior#
Polymorphic Rendering#
Use as to change the rendered HTML element or use a custom React component.
<InputText as={CustomInput} placeholder="Search..." />Render Function Children#
InputText accepts a render function as children, providing access to the component instance.
<InputText>{(instance) => <span>Custom render</span>}</InputText>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#
InputText#
| Name | Type | Default |
|---|---|---|
ref | Ref<unknown> | — |
| The reference to the component instance. | ||
pIf | boolean | true |
| Whether the component should be rendered. | ||
style | CSSProperties | ((instance?: InputTextInstance) => CSSProperties) | — |
| The style to apply to the component. | ||
className | string | ((instance?: InputTextInstance) => 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 | InputTextInstance | — |
| The instance to pass to the component. | ||
pt | SafeRecord<InputTextPassThrough> | — |
| 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: InputTextInstance) => 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. | ||
size | "small" | "large" | — |
| Defines the size of the InputText. | ||
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 | "inputtext" |
data-part | "root" |
Defines passthrough(pt) options of InputText component.
| label | type | description |
|---|---|---|
| root | InputTextPassThroughType<InputHTMLAttributes<HTMLInputElement>> | Used to pass attributes to the root's DOM element. |
Accessibility#
Screen Reader#
InputText renders a native input element. Provide an accessible name with a visible label, aria-label, or aria-labelledby.
Keyboard Support#
InputText uses native text input keyboard behavior.