Configuring the Pagefind search in the browser

The behaviour of the Pagefind search API can be configured in the browser.

UI (declarative)

If using the Component UI, options can be set declaratively with the <pagefind-config> element:

<pagefind-config base-url="/"></pagefind-config>

<pagefind-input></pagefind-input>
<pagefind-results></pagefind-results>

See the full list of available attributes in the <pagefind-config> reference.

UI (programmatic)

Options can be passed through to Pagefind via configureInstance. Import the function based on how you installed the Component UI:

// If installed via a package manager:
import { configureInstance } from '@pagefind/component-ui';
// If loaded via script tag:
const { configureInstance } = window.PagefindComponents;

configureInstance("default", {
    baseUrl: "/",
    // ... more search options
});

Search API

If interfacing with Pagefind directly, options can be passed via awaiting pagefind.options():

const pagefind = await import("/pagefind/pagefind.js");
await pagefind.options({
    baseUrl: "/",
    // ... more search options
});

Available options

Base URL

Defaults to “/”. If hosting a site on a subpath, baseUrl can be provided, and will be appended to the front of all search result URLs.

UI (declarative)

<pagefind-config base-url="/docs/"></pagefind-config>

UI (programmatic)

configureInstance("default", {
    baseUrl: "/docs/"
});

Search API

await pagefind.options({
    baseUrl: "/docs/"
});

Bundle path

Overrides the bundle directory. In most cases this should be automatically detected by the import URL. Set this if search isn’t working and you are seeing a console warning that this path could not be detected.

UI (declarative)

<pagefind-config bundle-path="/subpath/pagefind/"></pagefind-config>

UI (programmatic)

configureInstance("default", {
    bundlePath: "/subpath/pagefind/"
});

Search API

await pagefind.options({
    basePath: "/subpath/pagefind/"
});

Note: When using the Search API directly, the option is called basePath. It is usually auto-detected from the URL used to import pagefind.js, so you only need to set it if auto-detection fails.

Excerpt length

Set the maximum length for generated excerpts. Defaults to 30.

UI (declarative)

<pagefind-config excerpt-length="15"></pagefind-config>

UI (programmatic)

configureInstance("default", {
    excerptLength: 15
});

Search API

await pagefind.options({
    excerptLength: 15
});

Highlight query parameter

If set, Pagefind will add the search term as a query parameter under the same name.

If using the Pagefind highlight script, make sure this is configured to match.

UI (declarative)

<pagefind-config highlight-param="highlight"></pagefind-config>

UI (programmatic)

configureInstance("default", {
    highlightParam: "highlight"
});

Search API

await pagefind.options({
    highlightParam: "highlight"
});

Exact Diacritics

Defaults to false. When set to true, diacritics (accents such as àéö) are treated as fully distinct characters.

By default, Pagefind normalizes diacritics so that searching for “cafe” will match pages containing “café” and vice versa. When diacritics are normalized, exact matches are still preferred via the ranking.diacriticSimilarity parameter.

When exactDiacritics is set to true:

  • Searching for “café” will only match pages containing “café”
  • Searching for “cafe” will only match pages containing “cafe”

UI (declarative)

<pagefind-config exact-diacritics></pagefind-config>

UI (programmatic)

configureInstance("default", {
    exactDiacritics: true
});

Search API

await pagefind.options({
    exactDiacritics: true
});

Meta cache tag

By default, Pagefind appends a timestamp to the metadata request to ensure fresh data. If you’re building a PWA or offline-capable site, set this to a fixed string so that your service worker can cache the request. Change this value each time you rebuild your site. A build timestamp or random string works well.

The search index itself is unaffected and can always be cached.

UI (declarative)

<pagefind-config meta-cache-tag="abc123"></pagefind-config>

UI (programmatic)

configureInstance("default", {
    metaCacheTag: "abc123"
});

Search API

await pagefind.options({
    metaCacheTag: "abc123"
});

Ranking

See customize ranking

Index weight

See multisite search > weighting

Merge filter

See multisite search > filtering

Disable web worker

Defaults to false. If set to true, forces Pagefind to run all search operations on the main thread instead of using a web worker.

By default, Pagefind will attempt to use a web worker for search operations when available, which helps keep the main thread responsive during searches. If web workers are not supported or fail to initialize, Pagefind will automatically fall back to running on the main thread.

UI (declarative)

<pagefind-config no-worker></pagefind-config>

UI (programmatic)

configureInstance("default", {
    noWorker: true
});

Search API

await pagefind.options({
    noWorker: true
});
References