Skip to main content
Get DocSearch integrated into your documentation site in just a few minutes. This guide will walk you through installing DocSearch and implementing search for both JavaScript and React applications.
Don’t have your Algolia credentials yet? Apply to DocSearch to get free access for your open-source documentation.

What You’ll Need

Before you begin, you’ll need:
  • An Algolia Application ID (appId)
  • An Algolia Search-Only API Key (apiKey)
  • Your DocSearch Index Name (indexName)
If you’re using the free DocSearch program, you’ll receive these credentials after your application is approved.

Choose Your Implementation

DocSearch is available as both a vanilla JavaScript package and a React component. Choose the implementation that matches your documentation framework:

JavaScript

For vanilla JavaScript, HTML sites, or any framework

React

For React, Next.js, Gatsby, or React-based frameworks

JavaScript Implementation

Installation

Install the JavaScript package using your preferred package manager:
Alternatively, you can use the CDN version without a package manager:

Add a Container

Add a container element to your HTML where DocSearch will render:
index.html
Use a container element like <div>, not an <input>. DocSearch generates a fully accessible search box for you.

Initialize DocSearch

Import and initialize DocSearch with your credentials:
main.js

Programmatic Control

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

Complete Example

Here’s a complete working example:

React Implementation

Installation

Install the React package using your preferred package manager:
Alternatively, use the CDN version:

Basic Usage

Import the DocSearch component and render it in your application:
App.jsx

TypeScript Support

DocSearch has full TypeScript support with type definitions included:
App.tsx

Using a Ref

Access the DocSearch instance programmatically using a ref:

Complete Example

Here’s a complete React example with customization:

Verify It’s Working

After implementing DocSearch, you should see:
1

Search Button Appears

A search button with the text “Search” (or your custom text) and keyboard shortcut hint (Ctrl+K or ⌘K) appears in your application.
2

Modal Opens on Click

Clicking the search button or pressing Ctrl+K (⌘K on Mac) opens the search modal.
3

Search Returns Results

Typing a query returns relevant results from your documentation index.
4

Navigation Works

Clicking a result navigates to the corresponding documentation page.
If you’re not seeing results, verify that:
  • Your credentials are correct
  • Your index has been crawled and contains documents
  • Your API key has search permissions for the index

Import Styles

Both implementations require importing the CSS styles. DocSearch provides styles as a separate package:
The styles include:
  • Search button styling
  • Modal and overlay styling
  • Result list styling
  • Responsive design for mobile devices
  • Dark mode support (automatic based on system preferences)

Keyboard Shortcuts

DocSearch comes with built-in keyboard shortcuts: You can customize which shortcuts are enabled:

Next Steps

Now that you have DocSearch working, explore these features:

Styling

Customize colors, fonts, and layout to match your brand

API Reference

Explore all configuration options and methods

Advanced Features

Learn about transformItems, custom components, and more

Ask AI

Enable AI-powered conversational search

Troubleshooting

Search button not appearing

Make sure you’ve:
  1. Imported the CSS: import '@docsearch/css';
  2. Provided a valid container selector
  3. Called docsearch() after the DOM is ready

No search results

Check that:
  1. Your Algolia credentials are correct
  2. The index name matches your DocSearch index
  3. Your index has been crawled and populated
  4. Your API key has search permissions

Styles not loading

Ensure:
  1. You’ve imported @docsearch/css in your entry file
  2. Your bundler is configured to handle CSS imports
  3. The CSS is loaded before rendering the component

TypeScript errors

DocSearch includes TypeScript definitions. Make sure:
  1. You’re using @docsearch/react@4 or @docsearch/js@4
  2. Your tsconfig.json includes the node_modules directory
  3. You’re importing types correctly: import type { DocSearchProps } from '@docsearch/react';

Get Help

If you need assistance: