One border and one focus ring around an input and its addons. The group draws the ring through :focus-within and turns red through :has(:user-invalid), the inner input has no border of its own. Order in the DOM is the order on screen. Server component, no JavaScript.
Browser Support
Baseline Widely available2 featuresDetails
Draws the focus ring around the whole group
Turns the group border red when the inner input is invalid. Without it the border stays neutral
Preview
Installation
Usage
import { Search } from "lucide-react"
import {
InputGroup,
InputGroupAddon,
InputGroupInput,
} from "@/components/ui/input-group"
export default function Example() {
return (
<InputGroup>
<InputGroupAddon>
<Search />
</InputGroupAddon>
<InputGroupInput type="search" aria-label="Search" placeholder="Search…" />
</InputGroup>
)
}Examples
Clear animation
Type something and press the X, or select the text and press Delete. The X pops in and the placeholder slides back. Pure CSS, no JavaScript.
<InputGroup>
<InputGroupAddon>
<Search />
</InputGroupAddon>
<InputGroupInput
type="search"
aria-label="Search"
placeholder="Search…"
/>
</InputGroup>Text prefix and suffix
InputGroupText holds a short label before or after the value.
<InputGroup>
<InputGroupAddon>
<InputGroupText>https://</InputGroupText>
</InputGroupAddon>
<InputGroupInput aria-label="Domain" placeholder="example" />
<InputGroupAddon>
<InputGroupText>.com</InputGroupText>
</InputGroupAddon>
</InputGroup>Button
InputGroupButton is a small Button for an action next to the input.
<InputGroup>
<InputGroupAddon>
<AtSign />
</InputGroupAddon>
<InputGroupInput type="email" aria-label="Email" placeholder="name@example.com" />
<InputGroupAddon>
<InputGroupButton variant="secondary">Subscribe</InputGroupButton>
</InputGroupAddon>
</InputGroup>Validation
The group reacts to the input: :user-invalid and aria-invalid turn the border red.
<InputGroup>
<InputGroupAddon>
<AtSign />
</InputGroupAddon>
<InputGroupInput type="email" aria-label="Email" aria-invalid="true" />
</InputGroup>Props
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | - | Additional CSS classes |
Parts
| Part | Element | Description |
|---|---|---|
| InputGroup | div | Border, focus ring and invalid state; role="group" |
| InputGroupAddon | div | Slot before or after the input for an icon, text or button |
| InputGroupText | span | Text inside an addon |
| InputGroupInput | input | Borderless input; takes all the remaining width |
| InputGroupButton | button | Button for an addon; ghost and small by default |