Dark Mode Toggle (No Flash)
An accessible theme switch that follows the system setting, remembers the visitor's choice and never flashes white on load.
⚑ Report this
An accessible theme switch that follows the system setting, remembers the visitor's choice and never flashes white on load.
The download has a working demo (index.html) plus the files to copy. The key file is shown below with a Copy button.
// Dark Mode Toggle · Cube Burst Studios · CC0
// Follows the system setting until the visitor chooses; remembers the choice. Put the inline snippet from
// index.html in <head> so there's no white flash on load.
const KEY = "theme";
export function initThemeToggle(button) {
const root = document.documentElement;
const set = (theme, save) => {
root.dataset.theme = theme;
button.setAttribute("aria-pressed", String(theme === "dark"));
button.querySelector("[data-label]").textContent = theme === "dark" ? "Dark" : "Light";
if (save) try { localStorage.setItem(KEY, theme); } catch {}
};
set(root.dataset.theme || (matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"), false);
button.addEventListener("click", () => set(root.dataset.theme === "dark" ? "light" : "dark", true));
matchMedia("(prefers-color-scheme: dark)").addEventListener("change", (e) => {
let saved = null;
try { saved = localStorage.getItem(KEY); } catch {}
if (!saved) set(e.matches ? "dark" : "light", false);
});
}MORE
WEB DEV
View all ↗Game Landing Page Template
A complete one-page site for your game: sticky nav, hero with Play button, trailer slot, features, FAQ and a call-to-action band.
Memphis Pattern Backgrounds
Eight pure-CSS repeating patterns (stripes, dots, grid, zigzag, waves, checker, triangles, confetti). Recolour with two variables.
Infinite Marquee (Accessible)
A seamless scrolling ticker that pauses on hover/focus and stops for reduced-motion users. Works with text, chips or logos.
CSS Pixel Art + Generator
Crisp pixel art with no images: a pure-CSS beating heart, plus a tiny JS helper that turns a text grid into box-shadow sprites.