Skip to main content

Usage

Return Value

Features

  • Automatically updates when system preference changes
  • Works with both modern and legacy browsers
  • Handles SSR environments gracefully

Examples

Conditional Styling

With Theme Provider

Image Variants

Browser Support

The hook uses the prefers-color-scheme media query:
It supports both modern browsers (using addEventListener) and legacy browsers (using the deprecated addListener method).

SSR Considerations

When running on the server (where window is undefined), the hook defaults to "light" mode. The actual system preference will be detected on the client after hydration.
Last modified on December 22, 2025