Theme Toggle

A light/dark mode switch: moon while the page is light, sun while it is dark. The choice persists across visits.

Default

Click to flip this page between light and dark. The runtime toggles the dark class on the document root, mirrors color-scheme, and stores the choice under the theme localStorage key; with nothing stored it follows the OS preference.

Custom label

The accessible name doubles as the hover title, and extra classes fuse after the recipe classes.

Behavior

  • The icon swap is pure CSS via the root dark class - the runtime never touches the icons, so there is no flash of the wrong icon.
  • Multiple toggles on one page stay in agreement: they all read and write the same document class and storage key.
  • On pages that render a toggle, the runtime applies the stored or OS-preferred theme on load. Pages without one are left untouched.
Open Markdown
FreeTheme Toggle

Light/dark mode switch with persistence.

Install with the Proa CLI
proa ui add theme_toggle

Installs the reviewed component source, dependencies, shared support files, and required legal notices.

CLI and registry setup
recipe.rs
// SPDX-FileCopyrightText: 2026 Proa Labs, Inc.
// SPDX-License-Identifier: (MIT OR Apache-2.0) AND MIT

//! Theme Toggle recipe — named slot classes for the theme toggle button.

use crate::theme::rounded;
use crate::tw_join;
use proa_core::shared::attr_value::AttrValue;
use proa_core::{DataLoader, WebContext, WriteBuf, WriteError};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct ThemeToggleRecipeProps;

/// Static named classes for every Theme Toggle part.
#[derive(Debug, Clone, Copy)]
pub struct ThemeToggleRecipe {
    pub root: &'static str,
    pub moon_icon: &'static str,
    pub sun_icon: &'static str,
}

impl ThemeToggleRecipe {

Search

Type at least 2 characters

Customize

Make it yours

Palette

Radius

Overview
Components
Settings

Build your own

Themed Proa UI surface

Preview
Components52
RecipesTyped
customer-portal