# Fumadocs UI (the default theme of Fumadocs): Search UI
URL: /docs/ui/search
Source: https://raw.githubusercontent.com/fuma-nama/fumadocs/refs/heads/main/apps/docs/content/docs/ui/search.mdx

The UI for document search

## Overview [#overview]

You can customize Search UI from [`<RootProvider />`](/docs/ui/layouts/root-provider).

```tsx title="app/layout.tsx"
import { RootProvider } from 'fumadocs-ui/provider/<framework>';
import type { ReactNode } from 'react';
import { SearchDialog } from '@/components/my-search-dialog';

export default function Layout({ children }: { children: ReactNode }) {
  return (
    <html>
      <body>
        <RootProvider
          // [!code highlight:4]
          search={{
            enabled: false, // disable search entirely
            SearchDialog, // replace search dialog
          }}
        >
          {children}
        </RootProvider>
      </body>
    </html>
  );
}
```

### Hot Keys [#hot-keys]

Customize the hot keys to trigger search dialog, by default it's <kbd>⌘</kbd> <kbd>K</kbd> or <kbd>Ctrl</kbd> <kbd>K</kbd>.

```tsx
import { RootProvider } from 'fumadocs-ui/provider/<framework>';

<RootProvider
  search={{
    hotKey: [
      {
        display: 'K',
        key: 'k', // key code, or a function determining whether the key is pressed
      },
    ],
  }}
>
  {children}
</RootProvider>;
```

### References [#references]

A full list of options.

### SearchProps

| Prop            | Type                                                         | Description                                                                                                                                                                      |
| --------------- | ------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `preload?`      | `boolean \| undefined`                                       | **Deprecated.** Preload search dialog before opening it Default: `` `true` ``                                                                                                    |
| `links?`        | `SearchLink[] \| undefined`                                  | Custom links to be displayed if search is empty                                                                                                                                  |
| `hotKey?`       | `HotKey[] \| undefined`                                      | Hotkeys for triggering search dialog Default: `Meta/Ctrl + K`                                                                                                                    |
| `SearchDialog?` | `React.ComponentType<DefaultSearchDialogProps> \| undefined` | Replace default search dialog, allowing you to use other solutions such as Algolia Search It receives the `open` and `onOpenChange` prop, can be lazy loaded with `React.lazy()` |
| `options?`      | `Partial<DefaultSearchDialogProps> \| undefined`             | Additional props to the dialog                                                                                                                                                   |
| `enabled?`      | `boolean \| undefined`                                       | Enable search functionality Default: `` `true` ``                                                                                                                                |

## Custom UI [#custom-ui]

Fumadocs UI also exposes a lower level `<SearchDialog />` component for advanced use, you can create your own search dialog to replace the default one.

```tsx twoslash
'use client';
import React from 'react';
import { useFetchSearch } from 'fumadocs-core/search/client';
import {
  SearchDialog,
  SearchDialogClose,
  SearchDialogContent,
  SearchDialogHeader,
  SearchDialogFooter,
  SearchDialogIcon,
  SearchDialogInput,
  SearchDialogList,
  SearchDialogOverlay,
  type SharedProps,
} from 'fumadocs-ui/components/dialog/search';
import { useI18n } from 'fumadocs-ui/contexts/i18n';

export default function DefaultSearchDialog(props: SharedProps) {
  const { locale } = useI18n(); // (optional) for i18n
  const search = useFetchSearch({
    locale,
  });

  return (
    <SearchDialog {...search} {...props}>
      <SearchDialogOverlay />
      <SearchDialogContent>
        <SearchDialogHeader>
          <SearchDialogIcon />
          <SearchDialogInput />
          <SearchDialogClose />
        </SearchDialogHeader>
        <SearchDialogList />
        <SearchDialogFooter>{/* footer items */}</SearchDialogFooter>
      </SearchDialogContent>
    </SearchDialog>
  );
}
```

### Content Renderer [#content-renderer]

To render the Markdown content of search items on your own instead, pass `renderMarkdown`.

```tsx title="components/search.tsx"
<SearchDialogList
  // [!code highlight:8]
  Item={(props) => (
    <SearchDialogListItem
      {...props}
      renderMarkdown={(text) => {
        // ...
      }}
    />
  )}
/>
```

### Tables [#tables]

Customize how tables in results are rendered. A custom `Table` renders the rows on its own:

```tsx title="components/search.tsx"
<SearchDialogList
  // show the rows without a card
  Table={({ table, Item, onSelect }) =>
    table.rows.map((row) => (
      <Fragment key={row.id}>{Item({ item: row, onClick: () => onSelect(row) })}</Fragment>
    ))
  }
/>
```

### Highlights [#highlights]

Matches of the search query are highlighted with the [CSS Custom Highlight API](https://developer.mozilla.org/en-US/docs/Web/API/CSS_Custom_Highlight_API), style them with `::highlight(fd-search)`.

```css title="global.css"
::highlight(fd-search) {
  color: var(--color-fd-primary-foreground);
  background-color: var(--color-fd-primary);
}
```

`<SearchDialogList />` highlights the query of `data` from `<SearchDialog />`, or the search input without it.

When rendering results on your own, highlight them with `useHighlightQuery()`.

```tsx title="components/search-result.tsx"
'use client';
import { useHighlightQuery } from 'fumadocs-core/search/client';
import type { ReactNode } from 'react';

export function SearchResult({ query, children }: { query: string; children: ReactNode }) {
  const ref = useHighlightQuery(query);

  return <div ref={ref}>{children}</div>;
}
```

Text inside elements with `data-highlight-ignore` is not highlighted, like the badges of components.