Skip to main content
DocSearch supports theme customization through the theme prop, which controls the visual appearance of the search modal and button.

Theme Type

The theme prop accepts a simple string value:

Usage

'dark' | 'light'
Controls the visual theme of DocSearch components. The theme affects:
  • Search button appearance
  • Modal background and text colors
  • Search results styling
  • Icon colors
  • Border and shadow styles

Dynamic Theme Switching

You can dynamically switch themes based on your application’s theme settings:

Custom Styling

While the theme prop provides basic light/dark mode support, you can further customize DocSearch appearance using CSS variables and custom CSS.

CSS Variables

DocSearch uses CSS custom properties that you can override:

Custom CSS Classes

You can target specific DocSearch classes for more granular control:

Example: Custom Brand Colors

Theme Implementation

The theme implementation in DocSearch uses a React hook that applies the appropriate CSS class to the document:
This means you can also manually set the theme by adding the data-theme attribute to your HTML element:

Best Practices

Always ensure DocSearch’s theme matches your site’s overall theme for a consistent user experience. Use dynamic theme switching to keep them in sync.
Always test your custom styling in both light and dark modes to ensure readability and proper contrast ratios.
Prefer CSS variables over hard-coded values for easier theme maintenance and consistency.
Consider detecting and respecting the user’s system theme preference using prefers-color-scheme media query.