# Pagefind Component UI - LLM Reference Guide This document teaches LLM agents how to use and operate the Pagefind Component UI system. The Component UI is a set of web components for building search interfaces on static sites. **Important:** The Component UI (`pagefind-component-ui.js`, web components like ``) replaces the old "Default UI" (`pagefind-ui.js`, `new PagefindUI()`). The Default UI is legacy and no longer recommended. Always use the Component UI described in this document for new projects. ## How Pagefind Works Pagefind is a two-step system: 1. **Build time:** After your static site is built, you run the Pagefind CLI. It crawls the HTML output and generates a search index plus the UI assets in a `/pagefind/` directory inside your build output. 2. **Browser:** The Component UI loads from that generated `/pagefind/` directory and provides instant client-side search with no server required. The CLI step is typically added as a post-build command: ```bash # After your site builds to a directory (e.g. "public", "_site", "dist", "out"): npx -y pagefind --site public ``` This generates `public/pagefind/` containing the search index, WASM binary, and UI files. The UI `` and ` ``` That's it. The trigger renders a "Search" button with a `Cmd+K`/`Ctrl+K` shortcut. Clicking it opens a full modal with input, results, and keyboard navigation — all auto-generated. ## Choosing an Approach **Modal** (`` + ``) — Best default choice. Works on any site without tight layout integration. The trigger can go in a nav bar, sidebar, or anywhere. The modal overlays the page. **Searchbox** (``) — A compact input with dropdown results. Use this when you want search embedded directly in your navigation or header, rather than in an overlay. Single element, self-contained. **Building blocks** (``, ``, ``, etc.) — Use these when you need full control over layout, such as a dedicated search page with filters in a sidebar and results in the main content area. These components auto-connect when placed on the same page. ## Installation ### Option 1: Bundled Files (static sites, most common) Best for: Hugo, Eleventy, Jekyll, Astro, or any static site where you include assets via HTML tags. ```html ``` ### Option 2: npm Package (JS framework sites) Best for: Next.js, SvelteKit, Nuxt, or other frameworks where you import modules in JavaScript. You will still need to run the Pagefind CLI as a post-build step to generate the search index. ```bash npm install @pagefind/component-ui ``` ```javascript import '@pagefind/component-ui'; import '@pagefind/component-ui/css'; ``` If your site is hosted on a subpath or your Pagefind bundle is in a non-standard location, use `` or `configureInstance` to point to the right directory. ## Overview Pagefind Component UI provides: - Web components that auto-connect and communicate via shared instances - Two prebuilt experiences: Modal search and Searchbox dropdown - Individual building blocks for custom layouts - Full accessibility (WAI-ARIA compliant) - Automatic translations for 40+ languages - CSS custom property theming --- ## Component Reference ### Prebuilt Full Experiences #### `` + `` Modal overlay search dialog. Most universal search UI. ```html ``` **`` Attributes:** | Attribute | Type | Default | Description | |-----------|------|---------|-------------| | `placeholder` | string | Language dependent | Text on trigger button | | `shortcut` | string | `"mod+k"` | Keyboard shortcut to open modal | | `hide-shortcut` | boolean | `false` | Hide keyboard shortcut display | | `compact` | boolean | `false` | Show only search icon, no text | | `instance` | string | `"default"` | Instance name | **`` Attributes:** | Attribute | Type | Default | Description | |-----------|------|---------|-------------| | `reset-on-close` | boolean | `false` | Clear input when modal closes | | `instance` | string | `"default"` | Instance name | **Modal Default Structure:** An empty `` works out of the box with no configuration needed. It auto-generates a complete internal structure with input, summary, results, and keyboard hints. You only need to provide children if you want to customize the modal's contents: ```html ``` **Modal Structural Components:** - `` - Fixed header (contains input, has mobile close button) - `` - Scrollable content area - `` - Optional fixed footer **Keyboard Shortcuts:** - `Cmd+K` (Mac) / `Ctrl+K` (Windows/Linux) opens modal from anywhere on page - Keyboard shortcut is suppressed when the user is focused on an ``, `