Get Started
Components
- Accordion
- Attachment
- Avatar
- Badge
- Breadcrumb
- Button
- Button Group
- Card
- Checkbox
- Code Block
- Collapsible
- Dialog
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input
- Input Group
- Input OTP
- Item
- Label
- Marker
- Message
- Number Flow
- Pagination
- Popover
- Progress
- Radio Group
- Select
- Slider
- Sonner
- Spinner
- Switch
- Tooltip
- Separator
- Sheet
- Tabs
- Textarea
- Toggle
- Toggle Group
- Trace
AI Elements
Libraries
Utilities
Your API key is encrypted and stored securely.
import { cn } from "@/lib/utils";
const Input = ({
className,
type,
...props
}: React.ComponentProps<"input">) => (
<input
className={cn(
"file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input flex h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
"focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]",
"aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
className
)}
data-slot="input"
type={type}
{...props}
/>
);
export { Input };Input is a single-line text field for forms and inline editing. It inherits all native <input> attributes and behaviors, and pairs with Field for labels and descriptions.
Installation
$ bunx --bun frakment add input$ npx frakment add input$ pnpm dlx frakment add input$ yarn dlx frakment add input
Copy and paste the following code into your project.
import { cn } from "@/lib/utils";
const Input = ({
className,
type,
...props
}: React.ComponentProps<"input">) => (
<input
className={cn(
"file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input flex h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
"focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]",
"aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
className
)}
data-slot="input"
type={type}
{...props}
/>
);
export { Input };Update the import paths to match your project setup.
Usage
import { Input } from "@/components/ui/input";<Input placeholder="Email" type="email" />Examples
Basic
"use client";
import { Input } from "@/components/ui/input";
export function InputBasic() {
return <Input className="max-w-xs" placeholder="Enter text" />;
}<Input placeholder="Enter text" />With label
Choose a unique username for your account.
"use client";
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field";
import { Input } from "@/components/ui/input";
export function InputField() {
return (
<Field className="max-w-xs">
<FieldLabel htmlFor="input-field-username">Username</FieldLabel>
<Input
id="input-field-username"
placeholder="Enter your username"
type="text"
/>
<FieldDescription>
Choose a unique username for your account.
</FieldDescription>
</Field>
);
}<Field>
<FieldLabel htmlFor="username">Username</FieldLabel>
<Input id="username" placeholder="Enter your username" />
<FieldDescription>
Choose a unique username for your account.
</FieldDescription>
</Field>Form
Use FieldGroup for multiple fields with consistent spacing.
We'll send updates to this address.
"use client";
import { Button } from "@/components/ui/button";
import {
Field,
FieldDescription,
FieldGroup,
FieldLabel,
} from "@/components/ui/field";
import { Input } from "@/components/ui/input";
export function InputFieldgroup() {
return (
<FieldGroup className="max-w-xs">
<Field>
<FieldLabel htmlFor="fieldgroup-name">Name</FieldLabel>
<Input id="fieldgroup-name" placeholder="Jordan Lee" />
</Field>
<Field>
<FieldLabel htmlFor="fieldgroup-email">Email</FieldLabel>
<Input
id="fieldgroup-email"
placeholder="name@example.com"
type="email"
/>
<FieldDescription>We'll send updates to this address.</FieldDescription>
</Field>
<Field orientation="horizontal">
<Button type="reset" variant="outline">
Reset
</Button>
<Button type="submit">Submit</Button>
</Field>
</FieldGroup>
);
}<FieldGroup>
<Field>
<FieldLabel htmlFor="name">Name</FieldLabel>
<Input id="name" placeholder="Jordan Lee" />
</Field>
<Field>
<FieldLabel htmlFor="email">Email</FieldLabel>
<Input id="email" type="email" placeholder="name@example.com" />
</Field>
<Field orientation="horizontal">
<Button type="submit">Submit</Button>
</Field>
</FieldGroup>Invalid
Set aria-invalid on the input, or data-invalid on the Field wrapper, to trigger destructive styling.
This field contains validation errors.
"use client";
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field";
import { Input } from "@/components/ui/input";
export function InputInvalid() {
return (
<Field className="max-w-xs" data-invalid>
<FieldLabel htmlFor="input-invalid">Invalid Input</FieldLabel>
<Input aria-invalid id="input-invalid" placeholder="Error" />
<FieldDescription>
This field contains validation errors.
</FieldDescription>
</Field>
);
}<Field data-invalid>
<FieldLabel htmlFor="email">Email</FieldLabel>
<Input id="email" aria-invalid />
<FieldDescription>This field contains validation errors.</FieldDescription>
</Field>Types
<Input type="email" placeholder="Email" />
<Input type="password" placeholder="Password" />
<Input type="search" placeholder="Search" />
<Input type="file" />In Context
Email field
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
export function InputEmail() {
return (
<div className="mx-auto flex w-full max-w-sm flex-col gap-2">
<Label htmlFor="email">Email</Label>
<Input id="email" placeholder="you@example.com" type="email" />
</div>
);
}Search bar
For an icon inside the input surface, use Input Group:
https://
"use client";
import { ArrowRightIcon, Search } from "lucide-react";
import {
InputGroup,
InputGroupAddon,
InputGroupButton,
InputGroupInput,
InputGroupText,
} from "@/components/ui/input-group";
export function InputGroupDemo() {
return (
<div className="flex w-full max-w-sm flex-col gap-3">
<InputGroup>
<InputGroupAddon>
<Search />
</InputGroupAddon>
<InputGroupInput placeholder="Search..." />
</InputGroup>
<InputGroup>
<InputGroupAddon>
<InputGroupText>https://</InputGroupText>
</InputGroupAddon>
<InputGroupInput placeholder="example.com" />
</InputGroup>
<InputGroup>
<InputGroupInput placeholder="Enter email" />
<InputGroupAddon align="inline-end">
<InputGroupButton size="icon-xs" variant="default">
<ArrowRightIcon />
</InputGroupButton>
</InputGroupAddon>
</InputGroup>
</div>
);
}States
| State | How |
|---|---|
| Default | — |
| Focus | keyboard focus on the field |
| Invalid | aria-invalid="true" |
| Disabled | disabled prop |
<Input aria-invalid="true" placeholder="Email" />
<Input disabled placeholder="Disabled" />API Reference
Input
Extends React.ComponentProps<"input">.
| Prop | Type | Default | Description |
|---|---|---|---|
type | string | "text" | Native input type. |
placeholder | string | — | Shown when the input is empty. |
value | string | — | Controlled value. |
defaultValue | string | — | Uncontrolled initial value. |
onChange | React.ChangeEventHandler<HTMLInputElement> | — | Fires on every keystroke. |
disabled | boolean | false | Removes the input from the tab order. |
aria-invalid | boolean | — | Marks the input as invalid; pair with aria-describedby. |
Accessibility
Inputrenders a native<input>. It has no label by default; always pair with aLabelorFieldLabel.- Use the native
typeattribute (email,url,tel,number) so mobile keyboards adapt. - Set
aria-invalidandaria-describedbyon error. Do not rely on a red border alone. disabledremoves the input from the tab order. For informational values, usereadOnly.
Best Practices
- Always label the input. Placeholders disappear after typing; labels stay.
- Use the native type.
email,url,tel, andnumbertrigger the right keyboard on mobile. - Show errors inline. Use
aria-invalidand a description below the input, not a toast. - Do not disable without reason. Disabled inputs are invisible to screen readers.
- Cap length with
maxLength. Do not rely on server-side validation alone.
Anatomy
import { Input } from "@/components/ui/input";
export function InputAnatomy() {
return (
<div className="flex flex-col gap-2">
<Input placeholder="Empty" />
<Input defaultValue="Filled" />
<Input aria-invalid placeholder="Invalid" />
</div>
);
}- Field — 36px height, 1px border, 6px radius
- Text — 14px, inherits
foreground - Placeholder —
muted-foreground, disappears on input - Focus ring —
ring-3inringcolor on focus
Related Components
- Field — label, description, and error wrapper
- Input Group — add icons and buttons
- Input OTP — one-time password input
- Textarea — multi-line variant