---
title: "Autocomplete"
description: "A text field that suggests values while you type. The text you type stays the value, so it fits a search field or a command palette."
url: https://gelatinui.com/components/autocomplete
markdown_url: https://gelatinui.com/components/autocomplete.md
access: free
install: "npx shadcn@latest add @gelatin-ui/autocomplete"
registry_item: https://gelatinui.com/r/autocomplete.json
version: "2026-11-08"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Autocomplete

> A text field that suggests values while you type. The text you type stays the value, so it fits a search field or a command palette.

Page: https://gelatinui.com/components/autocomplete

## When to use it

Best for: A text field that suggests values while people type, where free text stays valid.

- Use it when the text itself is the value and a suggestion only fills it in.
- Use `filter={null}` when a server gives the suggestions.
- Use `mode` (`list`, `both`, `inline`, `none`) to set how the list and the text act.
- Use `onClick` on an `AutocompleteItem` for a command. It runs on a press and on Enter.

## When not to use it

- When the value must be one item from a fixed list, use a [Combobox](https://gelatinui.com/components/combobox.md).
- For a short fixed list with no typing, use a [Select](https://gelatinui.com/components/select.md).
- For plain text with no suggestions, use an [Input](https://gelatinui.com/components/input.md).

## Notes for agents

- A click in the field does not open the list. `openOnInputClick` is off by default.
- `AutocompleteItem` has no selected state, because the text is the value.
- It has no chevron by default. Add `AutocompleteTrigger` for a button that opens the list.
- Translate `AutocompleteTrigger` with its `aria-label`. The default is "Show suggestions".
- Keep `AutocompleteStatus` and `AutocompleteEmpty` mounted.
- A search field puts a search icon in an `InputGroupAddon` at the start of `AutocompleteInputGroup`.

## Anatomy

```text
Autocomplete
├─ AutocompleteValue (0..n)
├─ AutocompleteInputGroup (0..n)
├─ AutocompleteTrigger (0..n)
├─ AutocompleteItem (0..n)
└─ AutocompleteSeparator (0..n)
```

## API reference

### Autocomplete

Also takes every prop of Base UI `Combobox.Root`: https://base-ui.com/react/components/combobox

### AutocompleteInputGroup

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |
| `size` | `ControlSize` | "default" | 24, 28, 32, or 36px: the field sizes of `controlVariants`. |

### AutocompleteTrigger

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |

Also takes every prop of Base UI `Autocomplete.Trigger`: https://base-ui.com/react/components/autocomplete

### AutocompleteItem

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |

Also takes every prop of Base UI `Autocomplete.Item`: https://base-ui.com/react/components/autocomplete

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| AutocompleteValue | `autocomplete-value` |  |  |  |
| AutocompleteInputGroup | `autocomplete-input-group` |  |  |  |
| AutocompleteTrigger | `autocomplete-trigger` | `data-popup-open` |  |  |
| AutocompleteItem | `autocomplete-item` | `data-highlighted` |  |  |
| AutocompleteSeparator | `autocomplete-separator` |  |  |  |

## Usage

The text is the value, so people can type what the list does not hold. Pass `items` for the suggestions.

The sample also uses `field`, which this add does not write. One command adds them with this item:

```bash
npx shadcn@latest add @gelatin-ui/autocomplete @gelatin-ui/field
```

```tsx title="city-search.tsx"
import {
  Autocomplete,
  AutocompleteClear,
  AutocompleteContent,
  AutocompleteEmpty,
  AutocompleteInput,
  AutocompleteInputGroup,
  AutocompleteItem,
  AutocompleteList,
} from "@/components/ui/autocomplete";
import { Field, FieldLabel } from "@/components/ui/field";

export function CitySearch({ cities }: { cities: string[] }) {
  return (
    <Field>
      <FieldLabel>City</FieldLabel>
      <Autocomplete items={cities}>
        <AutocompleteInputGroup>
          <AutocompleteInput placeholder="Search cities" />
          <AutocompleteClear aria-label="Clear text" />
        </AutocompleteInputGroup>
        <AutocompleteContent>
          <AutocompleteEmpty>No cities found.</AutocompleteEmpty>
          <AutocompleteList>
            {(city: string) => {
              return (
                <AutocompleteItem key={city} value={city}>
                  {city}
                </AutocompleteItem>
              );
            }}
          </AutocompleteList>
        </AutocompleteContent>
      </Autocomplete>
    </Field>
  );
}
```

## Compose

Rules:

- Compose the parts (`compose-parts`): Build each item from its named parts as children, and pass your text and icons in as parts.
- Every state is designed (`every-state`): Give each view of data its loading, empty, and error states: a skeleton in the final layout, an `Empty` with an illustration and one next action, and an error that says what failed and how to retry.

## Add it

```bash
npx shadcn@latest add @gelatin-ui/autocomplete
```

It adds 36 registry items: 33 files, 5796 lines, and the npm packages `@base-ui/react`, `@phosphor-icons/react`, `clsx`, `motion`, `tailwind-merge`, `tailwind-variants`.

## Built on

- [Combobox](https://gelatinui.com/components/combobox.md)
- [Separator](https://gelatinui.com/components/separator.md)

## For AI agents

- Every item, one file: https://gelatinui.com/llms.txt
- MCP server (`search_items`, `get_item`, `get_install_plan`): https://gelatinui.com/mcp

## Related

- [Combobox](https://gelatinui.com/components/combobox.md): Pick Combobox when the value must be one item, or several items, from a fixed list.
- [Input](https://gelatinui.com/components/input.md)
- [Select](https://gelatinui.com/components/select.md): Pick Select for a short fixed list where people pick with no typing.
- [Command](https://gelatinui.com/components/command.md): Pick Command for a ready command palette or quick switcher, with groups, an empty state, and a dialog.
- [Search Field](https://gelatinui.com/components/search-field.md): Pick Search Field for a plain search query with a shortcut, a clear button, and a debounce, with no popup.

## Keyboard

| Keys | Action |
| --- | --- |
| Down Arrow, Up Arrow | Opens the list, then moves the highlight. |
| Enter | Picks the highlighted suggestion. With no highlight, closes the list. |
| Escape | Closes the list. With the list closed, clears the text. |
| Home, End | Moves the caret to the start or the end of the text. |

## Accessibility

The input is a combobox, and the list is a listbox. The active row moves while focus stays in the input.

A `Field` with a `FieldLabel` names the input. The clear and trigger buttons stay out of the tab order.

On a coarse pointer, rows grow to 44px high. The text stays 14px.

## Motion

| Part | Motion |
| --- | --- |
| Open | popup · 150ms · ease-panel (0.2, 0.4, 0.2, 1) · fades in and scales from 95% |
| Close | popup-exit · 120ms · ease-out (0, 0, 0.2, 1) |
