Quick answer
A search box needs something to search. For a static AI-built website, Pagefind generates an index from your finished HTML and supplies a search interface.
Use this order:
- Identify the folder your website actually publishes.
- Choose which public content should be searchable.
- Add the search interface, then build and index the site.
- Test a known phrase, an unmatched query and a result link.
- Deploy the index with the pages and check again.
Pagefind is open source; this route does not require a paid search subscription. Your ordinary hosting costs still apply.
This guide fits sites where you can edit and deploy the generated HTML. It is not a promise that every hosted builder accepts the same code.
Step 1: Check the finished pages
Ask your coding assistant to identify the build command and output folder. A project might publish dist, public or a folder of plain HTML. The correct choice is the output your host serves, not whichever folder name appears in a tutorial.
Open one finished page and check whether its actual HTML contains the text you want to find. Pagefind works from static HTML output. An empty page that relies on a later browser request for all its content needs further work before this method can index that text.
Start with one reader task: “Find the parking instructions without opening every page.”
Write down the expected page and a phrase that genuinely appears there. Do not seed a demonstration with a phrase absent from your content, then judge every empty result as a broken search feature.
Step 2: Choose what belongs in the index
Index public information that visitors should find. Keep unfinished pages, local test files and unpublished material out of the deployed output.
Pagefind's indexing instructions let you mark a main content area:
<main data-pagefind-body> <h1>Getting Here</h1> <p>Accessible parking is beside the east gate.</p> </main> Once this marker exists anywhere on the site, pages without it are excluded from the index. Ask your assistant to apply it through the appropriate content template, not just one article you happened to test.
That behaviour can explain a missing page: a marked article layout may be indexed while an unmarked information page is not. Check the intended pages rather than automatically indexing everything.
Excluding a page from search does not protect its address. A deployed HTML file can still be reachable directly. Do not put private material online and rely on search exclusion to hide it.
Step 3: Add the search control
The current Pagefind Component UI guide provides a ready-made search dialog. Its basic integration uses these generated files and components:
<link href="/pagefind/pagefind-component-ui.css" rel="stylesheet" > <script src="/pagefind/pagefind-component-ui.js" type="module" ></script> <pagefind-modal-trigger></pagefind-modal-trigger> <pagefind-modal></pagefind-modal> Ask your assistant to integrate the control in the existing layout. Preserve the site's navigation and visible labels. The search button should be easy to discover without replacing a useful menu.
Those asset paths assume deployment at the domain root. A site published under a subdirectory needs paths suited to that location.
The files do not exist merely because the snippet mentions them. Pagefind creates them during indexing. A development preview opened before that step may show a missing or incomplete search feature.
Step 4: Build, then create the index
Run the website's existing build first. Then point Pagefind at the finished output.
For example, if the output really is dist, the official CLI pattern can be used like this:
npx -y pagefind@1.6.0 --site dist --serve The --site argument identifies the built HTML folder. The optional --serve starts a local preview after indexing.
This is a reference command, not a requirement to replace your project's package manager. Your assistant can use the equivalent supported command in that project.
You can give it this brief:
Add Pagefind search to this static website. Find the real build output and identify the public pages. Use the current official search interface and index instructions. Run indexing after the existing website build. Include the generated search bundle in deployment. Preserve navigation, content and unrelated work. Test a known phrase, an unmatched query and a result link. Test keyboard use and narrow screens. Show the diff, preview and actual results before publishing. The running instructions explain that Pagefind adds a search bundle inside the indexed output. Deploy that generated bundle along with the pages. Uploading only the HTML leaves the search control without its supporting files.
Step 5: Follow an actual search result
In the finished local preview, open Search and enter the known phrase from Step 1.
Check three things: the result appears, its title identifies the right page, and following it opens the promised information.
Then search for an unmistakably absent phrase. An understandable no-results message is a valid outcome. A blank interface, a script error or results from an old build require investigation.
Finally, put the mouse aside. Use Tab to reach the search control, activate it with the keyboard and reach a result. If you lose your place, inspect the actual focus behaviour; our keyboard-menu guide explains the same principle for navigation.
Repeat the search in a narrow phone view. The input, result and way to close the dialog should remain usable.
Worked example: a fictional workshop website
We built a local English demonstration with Pagefind 1.6.0. It contained three public content pages: Home, Getting Here and Workshop Questions. A separate utility page had no content marker and was excluded from search.
The Getting Here page contained this prepared text:
Accessible parking is beside the east gate. Follow the level path to the workshop entrance. In the actual browser search, “accessible parking” returned Getting Here. Following it opened /getting-here/, where the promised text appeared.
Actual screenshot of the fictional local demonstration. Open the image for the full-size result.
These were the observed checks:
| Check | Observed result |
|---|---|
| Search “accessible parking” in the interface | Getting Here appeared and opened |
| Search “zzunmatchedfern” | A no-results message appeared |
| Add “Bike racks are beside the entrance,” then rebuild the index | “bike racks” found Getting Here |
| Reach Search using Tab, then press Enter | The search dialog opened |
| Search at 390px and 320px widths | Results remained visible without page-level horizontal overflow |
Before the edit, a supplementary query through the actual Pagefind browser API found no “bike racks” result. The same API check found no result for the utility page's distinctive test word. The after-rebuild check used the visible interface.
This was a local implementation test with prepared content, not a measurement of search quality across every site or a test of a hosted builder.
Step 6: Keep search current after publishing
Include indexing in the release workflow after the website build. If a later build replaces the output folder without regenerating the index, search can lose its files or keep old content.
After deployment, open your real domain and repeat the known-phrase search. Follow the result using the actual search control, not a saved destination URL.
When you add a page, test a phrase unique to it. When you remove a page, check that its old result no longer appears after rebuilding and deploying.
This is the same destination check as our website link checklist: a result is useful only if it reaches the information its title promises.
If search is empty or missing
Check the small failure before rebuilding the whole website:
- Search assets return 404: confirm the generated bundle was deployed at the paths the page requests.
- Some pages are absent: inspect their built text and content markers.
- New wording is absent: confirm indexing ran after the latest content build.
- Scripts fail despite available files: inspect the actual browser error and the hosting guidance, including any existing Content Security Policy.
Do not disable security headers wholesale to make a demo work. Ask your assistant to identify the required change for your actual setup.
A local site-search index and Google's index are separate systems. A working search box does not establish Google inclusion or guarantee search traffic.
Sources and testing limits
Official documentation checked November 24, 2026: Pagefind overview, getting started, indexing scope, Component UI and running the CLI.
The local browser checks support only the observations listed above. No paid search service was purchased. Use the normal publishing checks and review the deployed version before calling your own integration complete.
