Input

Displays a form input field or a component that looks like an input field.

Installation

npx shadcn@latest add input

Usage

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.

PropTypeDefaultDescription
type"text" | "email" | "password" | "number" | "tel" | "url" | "file" | ..."text"The type of input field.
placeholderstring-Placeholder text for the input.
disabledbooleanfalseWhether the input is disabled.
classNamestring-Additional CSS classes to apply.
valuestring-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