Skip to content

Add manual dark/light mode toggle to sphinx13 theme #13766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

DivyaSimhadri1004
Copy link

This PR introduces a manual dark/light mode toggle to the sphinx13 theme in the Sphinx documentation project.

✨ Features:
Added a dark/light mode toggle button to the top-right corner of the header.

Implemented dark mode styles via CSS using a dark-mode class on the .

Utilized localStorage to remember the user's theme preference across sessions.

Ensured responsiveness and accessibility for a better user experience.

image image

@DivyaSimhadri1004
Copy link
Author

Hi maintainers 👋
I’ve added support for manual dark/light mode toggle to the sphinx13 theme.
It includes:

A header toggle button

LocalStorage for persistence

Full CSS implementation for dark mode
All checks have passed ✅

Kindly review and share your feedback. Would love to improve it further if needed! 😊

const savedTheme = localStorage.getItem('theme');
if (savedTheme === 'dark') {
htmlTag.classList.add('dark-mode');
toggleBtn.textContent = '☀️ Light Mode';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☀ï looks wrong here

@@ -6,6 +6,24 @@
{%- if not embedded and pagename == root_doc %}
<style>.related { display: none; }</style>
{%- endif %}
<script>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid inline scripts, let's move to a .js file for better caching.

d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"
></path>
<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54..."></path>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has truncated the SVG data

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert

@timhoffm
Copy link
Contributor

I'm not a HTML/CSS/js expert, but would it make sense to add some (or all) of the functionality to the basic themes so that all themes can more easily define dark/light mode. - I suspect a theme would need to individually place the buttons and define mode-dependent CSS, but the toggle logic could be common.

@DivyaSimhadri1004
Copy link
Author

Thanks for the feedback!

Moved the inline dark mode script to dark-mode.js as suggested

Reverted the unintended change to wrongenc.inc
Let me know if any other improvements are needed 😊

@DivyaSimhadri1004
Copy link
Author

Hi again! 👋

Thanks for the review — I’ve:

  • Moved the inline dark mode script into a separate dark-mode.js file (as suggested)
  • Reverted the unintended change to wrongenc.inc

However, I noticed some CI checks failed. From the logs, they don’t seem related to the changes I’ve made (which only touch layout, JS, and restore a test file).

Please let me know if there’s anything further you’d like me to change. 😊

@AA-Turner
Copy link
Member

The failures are related; you continue to have a broken SVG. Are you using an LLM to assist with this PR?

A

@AA-Turner AA-Turner added the awaiting:response Waiting for a response from the author of this issue label Aug 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting:response Waiting for a response from the author of this issue type:docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants