Skip to content

Dark Mode Toggle Implementation#1737

Open
funketyme wants to merge 3 commits into
foundeo:masterfrom
funketyme:1736_darkmode
Open

Dark Mode Toggle Implementation#1737
funketyme wants to merge 3 commits into
foundeo:masterfrom
funketyme:1736_darkmode

Conversation

@funketyme
Copy link
Copy Markdown

PR Summary

Adds a full light/dark theme toggle to CFDocs with persistence, OS preference support, and scoped dark-mode styling. Most notable change is switching CSS colors to custom properties.

What Changed

  • theme-switcher.js

    • Adds a light/dark toggle
    • Persists selection in localStorage
    • Detects OS prefers-color-scheme
    • Applies theme via html[data-theme="..."]
    • Supports keyboard activation and accessibility attributes
  • style.css

    • Converts key colors to CSS custom properties
    • Uses :root defaults for light mode
    • Uses @media (prefers-color-scheme: dark) for OS dark-mode defaults
    • Uses [data-theme="dark"] / [data-theme="light"] overrides for manual toggle
    • Overrides Bootstrap and prettify styles where necessary
  • layout.cfm

    • Adds the theme toggle icon to the navbar
    • Loads the theme switcher script

Implementation notes

  • Light mode remains the default appearance
  • Dark mode is applied only when explicitly requested or when OS prefers dark
  • Theme variables are used consistently across UI surfaces
  • Manual theme selection takes precedence over OS preference
  • Dark-mode styles are scoped to avoid changing light-mode behavior
  • If user explicitly toggles dark/light mode and wants to revert to OS preference, clear localStorage through Dev Tools > Application > Clear Site Data

funketyme added 3 commits May 29, 2026 17:48
- Reworked CSS to use custom properties/variables.
- Created theme-switcher.js to dynamically switch between light and dark modes.
- Single-line change to layout.cfm to reference new theme-switcher.js.
- Run Code and Default buttons now display correctly in dark mode.
- Navigation menu mouseovers now display correctly in dark mode.
- applyTheme() was incorrectly setting local storage values when OS preference was identified on load.
- this was preventing OS preference from being correctly identified in the future since local storage was already written.
- if OS preference is detected, no local storage is used.
- local storage is now only used when the user clicks the toggle.

To Test:
- Clear browser local storage
- Load site
- You should see your OS preference (light or dark mode)
- In your OS, switch modes (light to dark, or dark to light).
- The site in your browser should instantly change modes as well.
- Now, click the toggle on the web page (mode will change).
- Now, change OS theme (dark/light).  Web page mode will not change since toggle was set.
@funketyme
Copy link
Copy Markdown
Author

Here's a screenshot of the dark mode implementation.

Image

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.

1 participant