Skip to content

Styling with Utilities

Compose native Iced interfaces from atomic Tailwind CSS v4 classes. Every tw!() call validates class names, arbitrary expressions, and variant chains at compile time.

Compile-Time Validation & Typo Diagnostics

Section titled “Compile-Time Validation & Typo Diagnostics”

tw!() validates every class name during compilation. Misspelled utilities fail fast during cargo check with closest-match suggestions.

use iss::tw;
let card = tw!("p-5 bg-zinc-900/90 border border-zinc-800 rounded-2xl shadow-lg");
// Compile-time error with closest-match suggestion:
// let typo = tw!("p-4 bg-banana-500");

Arbitrary Values, calc(), and Custom Properties

Section titled “Arbitrary Values, calc(), and Custom Properties”
Feature tw!() Syntax Meaning in ISS
Arbitrary lengths w-[280px], p-[1.25rem], top-[12%] Exact pixel, rem (16px base), or percentage value
CSS calc() w-[calc(100px+2rem)], w-[calc(50%+25%)], p-[calc(1rem+4px)] Folded at compile time for matching length or angle units
Arbitrary colors bg-[#0f172a], text-[rgb(56,189,248)] Exact hex or RGB color parsed at compile time
Opacity modifier bg-violet-500/20, border-white/15, text-[#c4b5fd]/80 Scales the color alpha channel
Type disambiguation bg-[length:200px_100px], bg-[position:20%_40%] Tailwind v4 hint syntax for ambiguous property types
Important modifier p-6!, bg-rose-500!, hover:text-white! Trailing ! (or leading !) overrides base cascade rules

Static TwStyle handles and owned IssStyle builders both implement IntoIss and pass into any .tw(...) call or layout helper:

use iced::widget::{container, text};
use iss::typed::*;
let header = container(text("Inspector").tw(tw!("text-sm font-semibold text-white")))
.tw(
IssStyle::new()
.px(4)
.py(3)
.bg(palette::ZINC_900)
.border_b()
.border_color(palette::ZINC_800),
);