Skip to main content
DocSearch can be easily integrated into any website using vanilla JavaScript. This guide shows you how to add DocSearch to static sites, HTML pages, or any JavaScript application.

Overview

The @docsearch/js package provides a simple JavaScript API that works in any browser environment. You can use it with or without a build tool.

Installation

Install DocSearch using your preferred package manager:
Then import in your JavaScript:

Quick Start

1

Add a container element

Add a container element where DocSearch will render the search button:
Use a container element (like <div>), not an <input>. DocSearch generates a fully accessible search button for you.
2

Initialize DocSearch

Call the docsearch() function with your configuration:
3

Test it

Open your page and press Ctrl+K (or Cmd+K on Mac) to open the search modal. You can also click the search button that DocSearch creates.

Complete HTML Example

Here’s a complete working example using the CDN:
index.html

Configuration Options

Basic Configuration

The minimum required configuration:

Placeholder Text

Customize the search input placeholder:

Search Parameters

Add Algolia search parameters:

Transform Search Client

Modify the search client before queries:

Transform Items

Post-process search results:

Programmatic Control

The docsearch() function returns an instance with methods for programmatic control:

Lifecycle Callbacks

Listen to lifecycle events:

Ask AI Integration

Basic Ask AI

Enable AI-powered conversational search:

Ask AI with Configuration

Customize Ask AI behavior:

Open Ask AI Programmatically

Sidepanel Integration

For a better AI experience, use the sidepanel component:
1

Install sidepanel package

Or use the CDN:
2

Add sidepanel container

3

Initialize both components

Custom Templates

Customize how results are rendered using the hitComponent and resultsFooterComponent options:

Custom Hit Component

Translations

Customize UI text:

Module Bundler Example

If you’re using a bundler like Webpack, Vite, or Rollup:
main.js

Styling

Customize DocSearch appearance with CSS:
custom.css

Complete Production Example

Here’s a complete example with all best practices:
index.html

Troubleshooting

Search button not appearing

  1. Verify the container element exists: document.querySelector('#docsearch')
  2. Check browser console for errors
  3. Ensure DocSearch CSS is loaded
  4. Verify you’re calling docsearch() after DOM is ready
  1. Check if JavaScript errors are preventing execution
  2. Verify credentials are correct
  3. Test keyboard shortcut (Ctrl+K) and button click separately

No search results

  1. Verify your index has data in Algolia dashboard
  2. Check searchParameters.facetFilters aren’t too restrictive
  3. Test with a known indexed term
  4. Check browser network tab for API errors

Next Steps

API Reference

Explore all configuration options

Styling

Customize the appearance of DocSearch

Ask AI

Add AI-powered conversational search

React Integration

Use DocSearch with React