Input
Displays a form input field or a component that looks like an input field.
Installation
npx shadcn@latest add inputUsage
Import and use the input component in your project.
import { Input } from "@/components/ui/input"
export default function MyComponent() {
return <Input />
}Examples
Default
The default input field.
With Label
An input with a label.
File Input
An input for file selection.
Disabled
A disabled input field.
With Button
An input combined with a button.
Form
Using input in a form context.
API Reference
Props available for the Input component.
| Prop | Type | Default | Description |
|---|---|---|---|
| type | "text" | "email" | "password" | "number" | "tel" | "url" | "file" | ... | "text" | The type of input field. |
| placeholder | string | - | Placeholder text for the input. |
| disabled | boolean | false | Whether the input is disabled. |
| className | string | - | Additional CSS classes to apply. |
| value | string | - | The controlled value of the input. |
| onChange | (event: ChangeEvent<HTMLInputElement>) => void | - | Callback function when the input value changes. |
Accessibility
Input component follows WAI-ARIA input pattern.
Labels
Always use a Label component associated with the input using the htmlFor attribute for better accessibility.
Keyboard Navigation
- Tab: Moves focus to or away from the input
- Typing updates the input value
Components
On This Page