DocSearch provides a standalone JavaScript package that works in any web application without requiring a framework. The package internally uses Preact for rendering while exposing a simple vanilla JS API.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/algolia/docsearch/llms.txt
Use this file to discover all available pages before exploring further.
Installation
Install the@docsearch/js package using your preferred package manager:
CDN Installation
If you prefer not to use a package manager, you can load DocSearch directly from a CDN:Basic Setup
Add a container element
Add a container element to your HTML where DocSearch will be rendered. DocSearch generates a fully accessible search box for you, so use a container element (like a
div), not an input:Don’t have your Algolia credentials yet? Apply to DocSearch to get started for free.
Complete Example
Here’s a complete working example:index.html
API Reference
docsearch(props)
The main function that initializes DocSearch and returns a control instance.Parameters
The container for your DocSearch component. Can be a CSS selector string or an HTMLElement.
Your Algolia application ID.
Your Algolia Search API key (public, search-only key).
The name of your Algolia index to search.
Placeholder text for the search input. Defaults to “Search docs”.
Additional Algolia search parameters to apply to all queries.
Hook to transform search results before rendering.
Custom component to render individual search results. Supports JSX, HTML strings with the
html helper, or function-based templates.Custom component rendered at the bottom of the results panel.
Hook to wrap or modify the Algolia search client.
Maximum number of results to show per category. Defaults to 5.
Disable storage and display of recent and favorite searches. Defaults to
false.Query string to prefill when opening the search modal.
Return Value
Thedocsearch() function returns a DocSearchInstance object with the following methods:
Returns
true once the component is mounted and ready.Returns
true if the modal is currently open.Opens the search modal programmatically.
Closes the search modal programmatically.
Opens Ask AI mode in the modal.
Unmounts the DocSearch component and cleans up resources.
Programmatic Control
You can control DocSearch programmatically using the returned instance:Lifecycle Callbacks
DocSearch supports lifecycle callbacks to hook into important events:Styling
DocSearch comes with default styles via@docsearch/css. You can customize the appearance by:
- CSS Variables: Override DocSearch’s CSS custom properties
- Custom Classes: Target DocSearch’s class names with your own CSS
- Theme Object: Pass a theme configuration (see React documentation)
Next Steps
Configuration
Learn about all available configuration options
Styling
Customize the appearance of your search
Ask AI
Enable AI-powered search assistance
API Reference
Explore the complete API documentation
