Skip to main content

Input group

Use an input group to add a prefix or suffix that clarifies units, symbols, or the information a text field expects.

Examples

Breakpoints

Mobile

320px

Mobile Lg

480px

Tablet

640px

Desktop

1024px
input-group-demo.tsx
import { Input, InputGroup } from '@uswds-tailwind/react'
export default function InputGroupDemo() {
return (
<div className="space-y-12">
<div className="max-w-xs">
<label htmlFor="card-number" className="block">Credit card number</label>
<InputGroup
startElement={(
<div aria-hidden="true" className="select-none pointer-events-none absolute left-0 whitespace-nowrap px-2 text-gray-50 flex items-center">
<div className="icon-[material-symbols--credit-card-outline] size-6" />
</div>
)}
>
<Input id="card-number" inputMode="numeric" autoComplete="cc-number" />
</InputGroup>
</div>
<div className="max-w-28">
<label htmlFor="weight" className="block">Weight, in pounds</label>
<InputGroup
endElement={(
<div aria-hidden="true" className="select-none pointer-events-none absolute right-0 whitespace-nowrap px-2 text-gray-50">
lbs.
</div>
)}
>
<Input id="weight" inputMode="decimal" />
</InputGroup>
</div>
</div>
)
}

Component API

Use InputGroup around a form control with optional leading or trailing content.

InputGroup<div>

Arranges the control and adjacent content.

PropTypeDescription
startElementReactNodeAdds content before the control.
endElementReactNodeAdds content after the control.