@docsearch/react package. This guide shows you how to set up DocSearch in your VitePress documentation site.
Overview
VitePress has built-in support for Algolia DocSearch through its default theme configuration. You can enable DocSearch by adding configuration to your VitePress config file.VitePress uses the same DocSearch integration that powers many documentation sites. Make sure you’ve applied for DocSearch to get your credentials.
Installation
No additional packages are required! VitePress includes DocSearch support out of the box. You just need to configure it.Configuration
1
Get your credentials
Before configuring DocSearch, you need:
appId- Your Algolia application IDapiKey- Your search-only API keyindexName- Your index name
2
Configure VitePress
Add the DocSearch configuration to your
.vitepress/config.js (or .ts, .mjs) file:.vitepress/config.js
3
Test your search
Restart your VitePress dev server and press
Ctrl+K (or Cmd+K on Mac) to open the search modal. You should see the DocSearch interface.Configuration Options
Basic Configuration
The minimum required configuration:.vitepress/config.js
Search Parameters
Customize search behavior with Algolia search parameters:.vitepress/config.js
Placeholder Text
Customize the search box placeholder:.vitepress/config.js
Translations
Customize button and modal text:.vitepress/config.js
Multi-Language Sites
For multi-language VitePress sites, configure search per locale:.vitepress/config.js
Custom Component Integration
If you need more control, you can directly use the@docsearch/react package in your custom VitePress theme.
1
Install DocSearch React
npm
2
Create a custom component
Create a Vue component that wraps DocSearch:
.vitepress/theme/components/DocSearch.vue
3
Use the component
Import and use your custom component in your VitePress theme:
.vitepress/theme/index.js
Ask AI Integration
Ask AI is available in DocSearch v4+. VitePress’s built-in integration may not support all Ask AI features. For full Ask AI support, use the custom component approach.
.vitepress/theme/components/DocSearch.vue
Crawler Configuration
VitePress sites require specific crawler configuration. Create adocsearch.config.json:
docsearch.config.json
Adjust selectors based on your custom VitePress theme. The default theme uses
.content for main content.Complete Example
Here’s a complete VitePress configuration with DocSearch:.vitepress/config.js
Troubleshooting
Search not working
- Check credentials: Verify your
appId,apiKey, andindexNameare correct - Index status: Ensure your index has been crawled and contains data
- Network: Check browser console for network errors
No results showing
- Crawler setup: Verify your crawler configuration matches your VitePress structure
- Facet filters: Check if
searchParameters.facetFiltersare too restrictive - Index content: Visit Algolia dashboard to inspect indexed records
Styling issues
- CSS conflicts: VitePress styles may conflict with DocSearch. Add custom CSS:
.vitepress/theme/custom.css
- Import order: Ensure DocSearch CSS is imported after VitePress theme CSS
Next Steps
Styling DocSearch
Customize the appearance to match your VitePress theme
API Reference
Explore all configuration options
Crawler Setup
Configure the DocSearch crawler for VitePress
Custom Integration
Build a custom integration with full control
