Skip to content

Conversation

@FazeelUsmani
Copy link

This commit adds automatic dark mode support to Sphinx's built-in themes (basic, classic, haiku, nature, and sphinxdoc) using CSS prefers-color-scheme media queries. The dark mode activates automatically based on the user's system/browser theme preference.

Additionally, an optional JavaScript toggle (theme_toggle.js) is provided in the basic theme to allow users to manually switch between light and dark modes, with the preference saved in localStorage.

Features:

  • Dark mode CSS for basic, classic, haiku, nature, and sphinxdoc themes
  • Automatic activation via prefers-color-scheme media query
  • Optional manual toggle with theme_toggle.js
  • Improved contrast and readability in dark mode
  • Support for both automatic and manual theme switching

Testing:

  • Manually tested with system dark mode enabled/disabled
  • Theme switching is instantaneous
  • All UI elements properly styled in both modes
  • Text remains readable with proper contrast ratios
  • Manual toggle persists preference across page loads

References

This commit adds automatic dark mode support to Sphinx's built-in themes
(basic, classic, haiku, nature, and sphinxdoc) using CSS prefers-color-scheme
media queries. The dark mode activates automatically based on the user's
system/browser theme preference.

Additionally, an optional JavaScript toggle (theme_toggle.js) is provided in
the basic theme to allow users to manually switch between light and dark modes,
with the preference saved in localStorage.

Features:
- Dark mode CSS for basic, classic, haiku, nature, and sphinxdoc themes
- Automatic activation via prefers-color-scheme media query
- Optional manual toggle with theme_toggle.js
- Improved contrast and readability in dark mode
- Support for both automatic and manual theme switching
@FazeelUsmani FazeelUsmani marked this pull request as draft November 11, 2025 09:51
@FazeelUsmani FazeelUsmani marked this pull request as ready for review November 11, 2025 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support dark mode for builtin themes

1 participant