-
-
Couldn't load subscription status.
- Fork 3.3k
Use data-theme attribute for theme switching and set color-scheme #1808
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds the CSS color-scheme property to the theme's color scheme definitions to ensure native HTML controls (such as form inputs, scrollbars, or embedded HTML elements) automatically adapt their appearance to match the selected dark or light mode.
Key Changes:
- Added
color-scheme: only light;to the light theme definition - Added
color-scheme: only dark;to the dark theme definition
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| assets/css/core/theme-vars.css | Added color-scheme property to both light and dark theme CSS class definitions |
| layouts/partials/head.html | Added color-scheme property to the inline dark theme CSS within the HTML head |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't change the browser theme to light/dark.
Use disableScrollBarStyle: true disable the scrollbar style so that the browser sets the mode.
|
Sorry wrong image attached. I've updated my comment above. |
|
Right, but if we are setting |
|
I assumed if the body is using dark scheme, scrollbars and other browser elements inside body should also be dark scheme for consistency. If we ever use native scrollbar, a dark-scheme page with ligh-scheme scroll bar shall look weird. Do you have some other consideration on that? Or, will it look better if I set the color-scheme on |
Refactor all other supporting elements
|
@taoyouh |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tested my scenario and it looked good with your changes. I have some additional suggestions: given we now set color-scheme we can use dark-light function to remove some css replications.
|
Looks good to me now |







What does this PR change? What problem does it solve?
When dark/light mode is selected, not only set the css colors but also set the color-scheme variable, so that native controls (if any, such as custom HTML embedded in markdown) have more natural color by default.
This pull request refactors the site's theme switching logic and CSS selectors to use the
data-themeattribute on thehtmlelement instead of toggling thedarkclass on thebody. This change improves consistency and maintainability for theme-dependent styles, and updates both the JavaScript and CSS to reflect the new approach. The most important changes are grouped below:Theme Switching Logic
data-themeattribute on thehtmlelement, replacing the previous use of thedarkclass on thebody. This affects files such asheader.htmlandfooter.html. [1] [2] [3]CSS Selector Updates
[data-theme="dark"]and[data-theme="light"]instead of.darkor:not(.dark), ensuring styles are applied based on thedata-themeattribute. This includes updates intheme-vars.css,header.css,post-single.css, andscroll-bar.css. [1] [2] [3] [4] [5]Theme Variable Improvements
color-schemeare now scoped to[data-theme="dark"]and[data-theme="light"], further aligning the code with the new theme management approach. [1] [2] [3]Scroll Bar and TOC Styling
data-themeattribute, ensuring correct appearance in both light and dark modes. [1] [2] [3]These changes make the theme system more robust and easier to extend, and ensure consistent behavior across the site.
Was the change discussed in an issue or in the Discussions before?
Not discussed before.
PR Checklist