Introducing PrimeReact v11-alpha 🎉Discover Now

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> with type="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#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: InputTextInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: InputTextInstance) => string)—
The class name to apply to the component.
asstring | 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.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceInputTextInstance—
The instance to pass to the component.
ptSafeRecord<InputTextPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: InputTextInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
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.
fluidboolean—
When enabled, the component will stretch to occupy the full width of its container.
invalidbooleanfalse
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.
AttributeValue
data-scope"inputtext"
data-part"root"

Defines passthrough(pt) options of InputText component.

labeltypedescription
rootInputTextPassThroughType<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.