shadcn.io is an independent project built on shadcn/ui
On this page9 sections
Input Group puts an icon, a fixed piece of text or a small button inside the same border as an input or a textarea: a search icon, a https:// prefix, a currency code, a copy button. The pieces read as one control, and clicking an icon or a prefix focuses the input.
To join full-size buttons to the side of a field, use a Button Group. For a field with nothing inside its border, a plain Input is enough.
Installation
Anatomy

Usage
<script lang="ts">
import { SearchIcon } from "lucide-svelte";
import {
InputGroup, InputGroupAddon, InputGroupInput,
} from "@/components/ui/input-group";
</script>
InputGroupInput is the input itself. Each InputGroupAddon shows where its align puts it, at the start of the row unless you say otherwise, whatever its place in the markup.
<InputGroup class="max-w-xs">
<InputGroupInput aria-label="Search" placeholder="Search..." />
<InputGroupAddon>
<SearchIcon aria-hidden="true" />
</InputGroupAddon>
<InputGroupAddon align="inline-end">12 results</InputGroupAddon>
</InputGroup>
Accessibility
InputGroup is a div with role="group", and the input inside it is a native <input> or <textarea> that needs a name of its own: a FieldLabel pointed at it, or an aria-label. An addon's text is not part of that name. Give an icon that only decorates aria-hidden, and a button that holds only an icon an aria-label, as the Button demo does. Clicking an addon anywhere but on a button focuses the input, which helps the pointer only. Keyboard focus moves through the input and the addon buttons in markup order, which align doesn't change.
- Tab
- Moves focus to the next focusable part, the input or a button in an addon, in the order they appear in the markup.
- Shift+Tab
- Moves focus to the previous focusable part.
- Enter
- On an addon button, presses it. In the input, submits the form around it, as any text input does.
- Space
- On an addon button, presses it.
Demos
Inline start
A search field with a magnifier in front of the text. align set to inline-start puts the addon at the start of the row, which is also where it goes when you leave align out. Start is a logical side, so on a right-to-left page the icon moves to the right with no change to the code.
Inline end
A password field with an eye-off icon at the end of the box, placed there by align set to inline-end. The end side follows the reading direction too. The icon here only decorates, so to show the password when it is pressed, make it an InputGroupButton, or use Password Input, which has the toggle built in.
Block start
Two headers inside the border, set with align to block-start: a Full Name caption over a one-line input, and a script.js file bar with a copy button over a code textarea. A block addon spans the full width, and the group grows taller to hold it. Use the top edge when the addon names or acts on the whole control.
Block end
Two footers, set with align to block-end: USD under an amount, and a 0/280 count with a Post button under a comment box. The count is fixed text in the demo, so update it from the textarea's length yourself. Use the bottom edge for a status about what was typed, or for the button that sends it.
Icon
Four fields with lucide icons: a search, an email, a card number between a card icon and a check, and a card number with a star and an info icon at the end. Every icon is aria-hidden, so each input carries an aria-label that says in words what its icon shows, such as Search or Email. With a visible label, use a FieldLabel instead.
Text
Fixed text that frames the value without being typed: $ and USD around an amount, https:// and .com around a domain, an @company.com suffix, and a characters-left note under a textarea. InputGroupText sets the string in the muted color. The value holds only what was typed, so add the prefix or suffix yourself when you save it.
Button
Three fields with buttons in their addons. A read-only URL ends in a copy button that turns into a check for two seconds, a rounded field opens a popover from an info button and toggles a star, and a search field ends in a Search button. InputGroupButton defaults to type="button", so none of them submits a form by accident.
Kbd
A search field with a magnifier at the start and a Kbd showing ⌘K at the end. The hint is plain text, so clicking it focuses the input like any other addon. The group doesn't listen for the shortcut, so bind ⌘K to focus the field yourself, and leave the hint out on touch screens.
Dropdown
A file name field ends in a more-actions button that opens Settings, Copy path and Open location, and a search field ends in a Search In button that picks where to search. Each trigger is an InputGroupButton, so pressing it opens its menu without click-to-focus pulling focus into the input. Use it for a choice about the field, such as its scope.
Spinner
Four fields in a busy state: a Spinner at the end, one at the start, one beside a Saving status, and a spinning loader icon with a Please wait note. Spinner has role="status" and the name Loading, while the plain loader icon is aria-hidden and says nothing to a screen reader. Show the spinner only while the request runs.
Textarea
A small code editor: a script.js bar with refresh and copy buttons on top, the code in an InputGroupTextarea, and a cursor position with a Run button at the bottom. A border-b and a border-t on the addons set the bars apart from the code. Clicking a bar's text focuses the textarea, as it would an input.
Custom
A plain <textarea> that grows with its content through the CSS field-sizing property, with a Submit button under it. It sets data-slot to input-group-control, the slot the group's focus ring looks for. InputGroupInput and InputGroupTextarea carry that slot already, so add it only to a control of your own.
RTL
The search field with a results count, two busy fields and the comment box, in Arabic, inside a wrapper with dir set to rtl. Inline addons follow the reading direction, so the search icon sits on the right and the count on the left, and ms-auto keeps Post at the end. Use logical classes like that in your own addons so they flip with the page.
FAQ
How do I put an Input Group addon before, after, above or below the input?
Set align on InputGroupAddon. inline-start, the default, puts it before the input and inline-end after it, on the same row. block-start and block-end put it above or below at full width, and the group grows taller to hold it, as the Block start and Block end demos show.
The sides are logical, so they swap on a right-to-left page. Where the addon sits in the markup doesn't change where it shows, but it does set the Tab order of any button inside it.
Why does clicking an Input Group addon focus the input?
InputGroup is UI SDK's, and a press on its own text or icons focuses its field, the way a label would, while a press on a button, a link or another control is left alone. That makes an icon or a prefix feel like part of the box. The field is the first <input> or <textarea> in the group, whatever its data-slot.
Click-to-focus is a convenience for the pointer. Keyboard users Tab straight to the input and to each addon button, so a click on the addon is never the only way in.
How do I add a label to an Input Group?
Label the input, not the group. Put a FieldLabel above the InputGroup inside a Field, and Field points it at the InputGroupInput for you. Without a visible label, set aria-label on the InputGroupInput.
An addon such as https:// or USD isn't part of the input's name. When the unit matters, put it in the label, such as Price in USD.
How do I show an Input Group as disabled or invalid?
Set disabled on the InputGroupInput, and it stops taking focus while the group's styles fade the whole box, addons and all. A button in an addon stays live, though, so disable each InputGroupButton as well, or a copy or clear button keeps working beside a field nobody can edit. The fade follows any disabled element inside the group, so a disabled button alone, such as a Send button waiting for text, fades the whole field too.
For an error, mark the input invalid with aria-invalid, or set invalid on the Field around the group, which passes aria-invalid to it. The group's styles look for an invalid control inside and turn the border around the whole group, addons and all, to the destructive color.
How do I change the height of an Input Group?
Set size on InputGroup to sm or lg for a group 28 or 36 pixels tall, and the InputGroupInput inside takes the same size unless you give it one of its own. The default, md, takes the height from the group's styles.
A group with a block addon or a textarea drops the fixed height and grows to fit. The width is the container's, because the group is w-full.
How do I put my own control, such as an autoresizing textarea, in an Input Group?
Give it data-slot set to input-group-control, as the Custom demo does with a self-sizing <textarea>. The group draws its focus ring by looking for a focused element with that slot, so without it the control sits inside the border but the ring never shows.
InputGroupInput and InputGroupTextarea set the slot already, and they are the better choice whenever they can do the job. The group's click-to-focus doesn't need it, since it focuses the first <input> or <textarea> inside.
How do I add a show password button to an Input Group?
Put an InputGroupButton in an addon with align set to inline-end, keep a boolean in state, and switch the input's type between password and text when the button is pressed. Give the button an aria-label that says what it will do, such as Show password, and swap its icon with the state.
The button is type="button" by default, so pressing it never submits the form. Password Input has this toggle built in, if you'd rather not wire it yourself.
Should I use an Input Group or a Button Group?
Use an Input Group when the input is the control and the extras live inside its border: an icon, a unit, a prefix, or a small button that acts on the value. Use a Button Group to join full-size buttons to one another or to the side of a field, each with its own border.
A Search button fits either one. Make it an InputGroupButton inside the border, as the last field of the Button demo does, when it should read as part of the box, and put it beside the field in a Button Group when it should look like a full-size button.
API Reference
InputGroup
<div> data-slot="input-group"
debug?boolean
Logs every state change with its reason to the console, in development builds.
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
- Type
Snippet<[{ props, state, children }]>
class?string
Merged with the part's classes.
data-disabled?string
Present while the field in the group is disabled, by itself or a <fieldset>.
data-filled?string
Present while the field in the group holds any text.
data-readonly?string
Present while the field in the group is read-only.
InputGroupAddon
<div> data-slot="input-group-addon"
align?"block-end" | "block-start" | "inline-end" | "inline-start"
Where it sits in the group: inline-start or inline-end beside the
input, block-start or block-end above or below it.
- Type
"block-end" | "block-start" | "inline-end" | "inline-start"- Default
"inline-start"
class?string
Merged with the part's classes.
data-align?string
Mirrors align.
InputGroupButton
clickEffect?boolean
Apply a click effect to the button.
- Default
true
debug?boolean
Logs every state change with its reason to the console, in development builds.
disabled?boolean
Stops presses. The button is natively disabled, so it leaves the tab order and its form doesn't submit through it, unless focusableWhenDisabled is set.
- Default
false
focusableWhenDisabled?boolean
Keeps a disabled button in the tab order with aria-disabled instead of the native attribute, so it can hold focus while it becomes disabled and host a tooltip that says why. Presses still do nothing.
- Default
false
isLoading?boolean
Show a loading indicator.
- Default
false
onclick?( event: MouseEvent, details?: ButtonActionDetails ) → unknown
Runs when the button is pressed. Return a Promise to keep it pending
(data-pending) until it settles. details.source says how it was
pressed; a wrapper passing the click on may leave it out.
- Type
( event: MouseEvent, details?: ButtonActionDetails ) → unknown- Parameters
event– React.MouseEvent<HTMLButtonElement>details?– ButtonActionDetails- Returns
unknown
pendingAnnouncement?string
What screen readers hear once the button has been pending for a second, so a slow action doesn't pass in silence. Set it in the page's language. An empty string says nothing.
- Default
"Loading"
pill?boolean
Fully rounded corners.
- Default
false
size?"icon-sm" | "icon-xs" | "sm" | "xs"
The size.
- Type
"icon-sm" | "icon-xs" | "sm" | "xs"- Default
"xs"
type?"button" | "submit" | "reset"
The button's type: button by default, so it never submits its form.
- Type
"button" | "submit" | "reset"- Default
"button"
variant?"default" | "destructive" | "ghost" | "link" | "outline" | "secondary"
Button's default: default.
- Type
"default" | "destructive" | "ghost" | "link" | "outline" | "secondary"- Default
"ghost"
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
- Type
Snippet<[{ props, state, children }]>
class?string
Merged with the part's classes.
data-size?string
Mirrors size.
InputGroupText
<span> data-slot="input-group-text"
class?string
Merged with the part's classes.
InputGroupInput
data-slot="input-group-control"
value?string | number
The value, for a controlled field. A number is written as its text, as a native input does. Two-way with bind:value.
- Type
string | number
defaultValue?string | number
The value it starts with. A form reset returns here.
- Type
string | number
onValueChange?(value: string, details: ChangeDetails<InputValueChangeReason>) → void
Called when the user changes the value: typing ("input-change"), a Clear part ("clear-press"), a form reset ("reset") or a controller ("imperative"). details.cancel() keeps the value as it was.
- Type
(value: string, details: ChangeDetails<InputValueChangeReason>) → void- Parameters
value– stringdetails– ChangeDetails<InputValueChangeReason>- Returns
void
controller?InputController
Reads and writes the field from anywhere. Create one with createInputController().
debug?boolean
Logs every state change with its reason to the console, in development builds.
disabled?boolean
Disables the field.
readOnly?boolean
Makes the field read-only.
required?boolean
Makes the field required.
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
- Type
Snippet<[{ props, state, children }]>
class?string
Merged with the part's classes.
InputGroupTextarea
data-slot="input-group-control"
value?string
The value, for a controlled field. Two-way with bind:value.
defaultValue?string
The value it starts with. A form reset returns here.
onValueChange?(value: string, details: ChangeDetails<InputValueChangeReason>) → void
Called when the user changes the value: typing ("input-change"), a Clear part ("clear-press"), a form reset ("reset") or a controller ("imperative"). details.cancel() keeps the value as it was.
- Type
(value: string, details: ChangeDetails<InputValueChangeReason>) → void- Parameters
value– stringdetails– ChangeDetails<InputValueChangeReason>- Returns
void
autoResize?boolean
Grows and shrinks with the text. Bound it with CSS min-height and max-height; past the maximum, it scrolls.
- Default
false
controller?InputController
Reads and writes the field from anywhere. Create one with createInputController().
debug?boolean
Logs every state change with its reason to the console, in development builds.
disabled?boolean
Disables the field.
onSubmit?(value: string, details: TextareaSubmitDetails) → void
Runs on the submit shortcut, unless an input method is composing. Without it, the shortcut submits the form the textarea is in. With neither, the key is left alone, so Enter adds a line.
- Type
(value: string, details: TextareaSubmitDetails) → void- Parameters
value– stringdetails– TextareaSubmitDetails- Returns
void
readOnly?boolean
Makes the field read-only.
required?boolean
Makes the field required.
submitShortcut?"enter" | "mod+enter"
Which keys submit: "enter", with Shift+Enter for a new line, or "mod+enter", with Enter for a new line. Without it, Enter always starts a new line.
- Type
"enter" | "mod+enter"
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
- Type
Snippet<[{ props, state, children }]>
class?string
Merged with the part's classes.











