Skip to content

Theme Variables

Define live design tokens with IssTheme or Tailwind CSS v4 @theme syntax via theme!(), then swap themes at runtime with theme_provider without recompiling or re-parsing utilities.

Interactive Iced
Rust · WASM
Live Rust Iced card mutating IssTheme @theme variables via Violet, Rose, and Emerald swatches
Click Violet, Rose, or Emerald to mutate live IssTheme @theme tokens at runtime

IssTheme supports every Tailwind CSS v4 token namespace: --color-*, --spacing, --spacing-*, --radius-*, --font-*, --text-*, --shadow-*, --ease-*, --breakpoint-*, --container-*, plus arbitrary custom properties (--*).

use std::sync::Arc;
use iced::widget::{button, text};
use iss::{col_tw, theme, theme_provider, tw, TwExt};
let royal = Arc::new(theme!(
r#"@theme {
--color-surface: #1b1729;
--color-brand: #7c3aed;
--color-orchid: #f5d0fe;
--radius-card: 16px;
}"#
));
let view = theme_provider(
royal,
col_tw(
[
text("Themed Card").tw(tw!("text-sm font-bold text-(--color-orchid)")),
button(text("Action").tw(tw!("text-xs font-semibold text-white")))
.on_press(Message::Action)
.tw(tw!("px-3 py-1.5 rounded-lg bg-(--color-brand) hover:bg-(--color-brand)/85")),
],
tw!("p-4 gap-3 rounded-(--radius-card) bg-(--color-surface)"),
),
);
Syntax Example Behavior
Shorthand (--var) bg-(--color-surface), p-(--spacing-card), rounded-(--radius-card) Resolves token live from nearest theme_provider
Alpha modifier (--var)/alpha bg-(--color-brand)/20, hover:bg-(--color-brand)/85 Applies opacity dynamically to resolved token color
Fallback [var(--a, fallback)] bg-[var(--color-accent,#7c3aed)], p-[var(--pad,12px)] Uses fallback value when the custom property is absent
Nested var() fallbacks text-[var(--fg-brand,var(--fg-default,#f8fafc))] Walks balanced nested fallbacks deterministically
Typed builder methods .bg_var("--color-surface"), .bg_var_alpha("--color-brand", 0.2) Live theme variable binding on IssStyle