Site Search
By default, Starlight sites include full-text search powered by Pagefind, which is a fast and low-bandwidth search tool for static sites.
No configuration is required to enable search. Build and deploy your site, then use the search bar in the site header to find content.
Hide content in search results
Exclude a page
To exclude a page from your search index, add pagefind: false
to the page’s frontmatter:
Exclude part of a page
Pagefind will ignore content inside an element with the data-pagefind-ignore
attribute.
In the following example, the first paragraph will display in search results, but the contents of the <div>
will not:
Alternative search providers
Algolia DocSearch
If you have access to Algolia’s DocSearch program and want to use it instead of Pagefind, you can use the official Starlight DocSearch plugin.
-
Install
@astrojs/starlight-docsearch
: -
Add DocSearch to your Starlight
plugins
config inastro.config.mjs
and pass it your AlgoliaappId
,apiKey
, andindexName
:
With this updated configuration, the search bar on your site will now open an Algolia modal instead of the default search modal.
Translating the DocSearch UI
DocSearch only provides English UI strings by default. Add translations of the modal UI for your language using Starlight’s built-in internationalization system.
-
Extend Starlight’s
i18n
content collection definition with the DocSearch schema insrc/content/config.ts
: -
Add translations to your JSON files in
src/content/i18n/
.These are the English defaults used by DocSearch: