Search every page in the navigation.
A text input component for forms and user data entry with built-in styling and accessibility features.
Your API key is encrypted and stored securely.
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"
import { Input } from "@/components/ui/input"
function InputDemo() {
return (
<Field>
<FieldLabel htmlFor="input-demo-api-key">API Key</FieldLabel>
<Input id="input-demo-api-key" type="password" placeholder="sk-..." />
<FieldDescription>
Your API key is encrypted and stored securely.
</FieldDescription>
</Field>
)
}
export default InputDemonpx shadcn@latest add @ziiz/inputimport { Input } from "@/components/ui/input"<Input />import { Input } from "@/components/ui/input"
function InputBasic() {
return <Input placeholder="Enter text" />
}
export default InputBasicUse the size prop for a 32, 36 or 40px field. The text inset follows: 12px at sm and default, 16px at lg, the same as a button of that size.
import { Input } from "@/components/ui/input"
function InputSize() {
return (
<div className="flex w-full max-w-xs flex-col gap-3">
<Input size="sm" placeholder="Small" />
<Input placeholder="Default" />
<Input size="lg" placeholder="Large" />
</div>
)
}
export default InputSizeUse the variant prop to change the field's look. default is the outlined field, secondary a gray fill that darkens on hover, and ghost is transparent with no hover, for a field on a toolbar or a surface of its own. They match the outline, secondary and ghost button. Focus darkens the default border; secondary and ghost stay as they rest and the caret shows focus.
import { Input } from "@/components/ui/input"
function InputVariants() {
return (
<div className="flex w-full max-w-xs flex-col gap-3">
<Input placeholder="Default" />
<Input variant="secondary" placeholder="Secondary" />
<Input variant="ghost" placeholder="Ghost" />
</div>
)
}
export default InputVariantsUse shape="rounded" for a pill. Only the radius changes, so the text inset is the same as a square field's.
import { Input } from "@/components/ui/input"
function InputRounded() {
return (
<div className="flex w-full max-w-xs flex-col gap-3">
<Input shape="rounded" placeholder="Email" />
<Input shape="rounded" variant="secondary" placeholder="Search" />
</div>
)
}
export default InputRoundedUse Field, FieldLabel, and FieldDescription to create an input with a
label and description.
Choose a unique username for your account.
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"
import { Input } from "@/components/ui/input"
function InputField() {
return (
<Field>
<FieldLabel htmlFor="input-field-username">Username</FieldLabel>
<Input
id="input-field-username"
type="text"
placeholder="Enter your username"
/>
<FieldDescription>
Choose a unique username for your account.
</FieldDescription>
</Field>
)
}
export default InputFieldUse FieldGroup to show multiple Field blocks and to build forms.
We'll send updates to this address.
import { Button } from "@/components/ui/button"
import {
Field,
FieldDescription,
FieldGroup,
FieldLabel,
} from "@/components/ui/field"
import { Input } from "@/components/ui/input"
function InputFieldgroup() {
return (
<FieldGroup>
<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"
type="email"
placeholder="name@example.com"
/>
<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>
)
}
export default InputFieldgroupUse the disabled prop to disable the input. To style the disabled state, add the data-disabled attribute to the Field component.
This field is currently disabled.
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"
import { Input } from "@/components/ui/input"
function InputDisabled() {
return (
<Field data-disabled>
<FieldLabel htmlFor="input-demo-disabled">Email</FieldLabel>
<Input
id="input-demo-disabled"
type="email"
placeholder="Email"
disabled
/>
<FieldDescription>This field is currently disabled.</FieldDescription>
</Field>
)
}
export default InputDisabledUse the aria-invalid prop to mark the input as invalid. To style the invalid state, add the data-invalid attribute to the Field component.
This field contains validation errors.
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"
import { Input } from "@/components/ui/input"
function InputInvalid() {
return (
<Field data-invalid>
<FieldLabel htmlFor="input-invalid">Invalid Input</FieldLabel>
<Input id="input-invalid" placeholder="Error" aria-invalid />
<FieldDescription>
This field contains validation errors.
</FieldDescription>
</Field>
)
}
export default InputInvalidUse the type="file" prop to create a file input.
Select a picture to upload.
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"
import { Input } from "@/components/ui/input"
function InputFile() {
return (
<Field>
<FieldLabel htmlFor="picture">Picture</FieldLabel>
<Input id="picture" type="file" />
<FieldDescription>Select a picture to upload.</FieldDescription>
</Field>
)
}
export default InputFileUse Field with orientation="horizontal" to create an inline input.
Pair with Button to create a search input with a button.
import { Button } from "@/components/ui/button"
import { Field } from "@/components/ui/field"
import { Input } from "@/components/ui/input"
function InputInline() {
return (
<Field orientation="horizontal">
<Input type="search" placeholder="Search..." />
<Button>Search</Button>
</Field>
)
}
export default InputInlineUse a grid layout to place multiple inputs side by side.
import { Field, FieldGroup, FieldLabel } from "@/components/ui/field"
import { Input } from "@/components/ui/input"
function InputGrid() {
return (
<FieldGroup className="grid max-w-sm grid-cols-2">
<Field>
<FieldLabel htmlFor="first-name">First Name</FieldLabel>
<Input id="first-name" placeholder="Jordan" />
</Field>
<Field>
<FieldLabel htmlFor="last-name">Last Name</FieldLabel>
<Input id="last-name" placeholder="Lee" />
</Field>
</FieldGroup>
)
}
export default InputGridUse the required attribute to indicate required inputs.
This field must be filled out.
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"
import { Input } from "@/components/ui/input"
function InputRequired() {
return (
<Field>
<FieldLabel htmlFor="input-required">
Required Field <span className="text-red-800">*</span>
</FieldLabel>
<Input
id="input-required"
placeholder="This field is required"
required
/>
<FieldDescription>This field must be filled out.</FieldDescription>
</Field>
)
}
export default InputRequiredUse Badge in the label to highlight a recommended field.
import { Badge } from "@/components/ui/badge"
import { Field, FieldLabel } from "@/components/ui/field"
import { Input } from "@/components/ui/input"
function InputBadge() {
return (
<Field>
<FieldLabel htmlFor="input-badge">
Webhook URL{" "}
<Badge variant="secondary" className="ml-auto">
Beta
</Badge>
</FieldLabel>
<Input
id="input-badge"
type="url"
placeholder="https://api.example.com/webhook"
/>
</Field>
)
}
export default InputBadgeTo add icons, text, or buttons inside an input, use the InputGroup component. See the Input Group component for more examples.
import { IconInfoCircle } from "@tabler/icons-react"
import { Field, FieldLabel } from "@/components/ui/field"
import {
InputGroup,
InputGroupAddon,
InputGroupInput,
InputGroupText,
} from "@/components/ui/input-group"
function InputInputGroup() {
return (
<Field>
<FieldLabel htmlFor="input-group-url">Website URL</FieldLabel>
<InputGroup>
<InputGroupInput id="input-group-url" placeholder="example.com" />
<InputGroupAddon>
<InputGroupText>https://</InputGroupText>
</InputGroupAddon>
<InputGroupAddon align="inline-end">
<IconInfoCircle />
</InputGroupAddon>
</InputGroup>
</Field>
)
}
export default InputInputGroupTo add buttons to an input, use the ButtonGroup component. See the Button Group component for more examples.
import { Button } from "@/components/ui/button"
import { ButtonGroup } from "@/components/ui/button-group"
import { Field, FieldLabel } from "@/components/ui/field"
import { Input } from "@/components/ui/input"
function InputButtonGroup() {
return (
<Field>
<FieldLabel htmlFor="input-button-group">Search</FieldLabel>
<ButtonGroup>
<Input id="input-button-group" placeholder="Type to search..." />
<Button variant="outline">Search</Button>
</ButtonGroup>
</Field>
)
}
export default InputButtonGroupA full form example with multiple inputs, a select, and a button.
import { Button } from "@/components/ui/button"
import {
Field,
FieldDescription,
FieldGroup,
FieldLabel,
} from "@/components/ui/field"
import { Input } from "@/components/ui/input"
import {
Select,
SelectContent,
SelectGroup,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select"
function InputForm() {
const countries = [
{ label: "United States", value: "us" },
{ label: "United Kingdom", value: "uk" },
{ label: "Canada", value: "ca" },
]
return (
<form className="w-full max-w-sm">
<FieldGroup>
<Field>
<FieldLabel htmlFor="form-name">Name</FieldLabel>
<Input
id="form-name"
type="text"
placeholder="Evil Rabbit"
required
/>
</Field>
<Field>
<FieldLabel htmlFor="form-email">Email</FieldLabel>
<Input id="form-email" type="email" placeholder="john@example.com" />
<FieldDescription>
We'll never share your email with anyone.
</FieldDescription>
</Field>
<div className="grid grid-cols-2 gap-4">
<Field>
<FieldLabel htmlFor="form-phone">Phone</FieldLabel>
<Input id="form-phone" type="tel" placeholder="+1 (555) 123-4567" />
</Field>
<Field>
<FieldLabel htmlFor="form-country">Country</FieldLabel>
<Select items={countries} defaultValue="us">
<SelectTrigger id="form-country">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectGroup>
{countries.map((country) => (
<SelectItem key={country.value} value={country.value}>
{country.label}
</SelectItem>
))}
</SelectGroup>
</SelectContent>
</Select>
</Field>
</div>
<Field>
<FieldLabel htmlFor="form-address">Address</FieldLabel>
<Input id="form-address" type="text" placeholder="123 Main St" />
</Field>
<Field orientation="horizontal">
<Button type="button" variant="outline">
Cancel
</Button>
<Button type="submit">Submit</Button>
</Field>
</FieldGroup>
</form>
)
}
export default InputForm