Skip to main content

Search

Add a search form to help visitors find site content. Compare default, large, and icon-button layouts.

Examples

Default

Breakpoints

Mobile

320px

Mobile Lg

480px

Tablet

640px

Desktop

1024px
search-demo.tsx
import { Search } from '@uswds-tailwind/react'
export default function SearchDemo() {
return (
<div className="max-w-lg">
<Search.Root>
<Search.Label>Search</Search.Label>
<Search.Input />
<Search.Button>Search</Search.Button>
</Search.Root>
</div>
)
}

Large

Breakpoints

Mobile

320px

Mobile Lg

480px

Tablet

640px

Desktop

1024px
search-large-demo.tsx
import { Search } from '@uswds-tailwind/react'
export default function SearchLargeDemo() {
return (
<div className="max-w-lg">
<Search.Root size="lg">
<Search.Label>Search</Search.Label>
<Search.Input />
<Search.Button>Search</Search.Button>
</Search.Root>
</div>
)
}

Icon Button

Breakpoints

Mobile

320px

Mobile Lg

480px

Tablet

640px

Desktop

1024px
search-icon-button-demo.tsx
import { Search } from '@uswds-tailwind/react'
export default function SearchIconButtonDemo() {
return (
<div className="max-w-lg">
<Search.Root size="sm">
<Search.Label>Search</Search.Label>
<Search.Input />
<Search.Button aria-label="Search" />
</Search.Root>
</div>
)
}

Component API

Put Label, Input, and Button inside Root to form a search control.

Root<div>

Sets the shared search size and field state.

PropTypeDefaultDescription
sizedefault | sm | lgdefaultChanges the input and button size.
namestring—Form field name.
requiredboolean—Requires a query.
disabledboolean—Disables the search control.
AttributeValuePurpose
data-disabledPresent when disabledStyle the disabled state.

Label<label>

Provides a visually hidden accessible name.

AttributeValuePurpose
data-disabledPresent when disabledStyle the disabled state.

Input<input>

Receives the search query.

AttributeValuePurpose
data-disabledPresent when disabledStyle the disabled state.

Button<button>

Submits the search; children replace the default search icon. Give the icon-only button an accessible name, such as aria-label="Search".

AttributeValuePurpose
data-disabledPresent when disabledStyle the disabled state.