Skip to content

Styling Native Widgets

Call .tw(...) on any native Iced widget after importing TwExt, and use ISS layout helpers (row_tw, col_tw, flex_tw, grid_tw) for multi-child containers.

Interactive Iced
Rust · WASM
Live interactive native Iced text_input, button, and checkbox styled with .tw()
Type in the input, toggle the checkbox, and click Save

Every widget below accepts compile-time tw!("..."), typed IssStyle builders, or viewport-resolved vp.tw(...).

Iced Widget Common Classes Notes
container(...) p-*, w-*, h-*, bg-*, bg-linear-to-*, border, rounded-*, shadow-*, backdrop-blur-*, overflow-hidden Add overflow-hidden when flush children touch rounded-* corners
button(...) px-*, py-*, bg-*, hover:*, active:*, disabled:*, border, rounded-*, cursor-pointer Hover/active overrides automatically inherit base rounded-*, border, and shadow-*
text(...) text-sm, font-semibold, italic, leading-*, tracking-*, text-*, underline, truncate, line-clamp-* Wrap text inside button(text("Save").tw(...)) to style button label typography
text_input(...) px-*, py-*, bg-*, border, focus:border-*, placeholder:*, caret-*, rounded-* Use .tw_state(...) to drive invalid:* validation styles
checkbox(...) accent-*, border, rounded-*, checked:*, cursor-pointer accent-* sets the checked box fill color
scrollable(...) overflow-y-auto, scrollbar-thin, scrollbar-none, scrollbar-thumb-*, scrollbar-track-* Pair with max-h-* or min-h-0 inside flex columns
svg(...) w-*, h-*, opacity-* Use svg_tw / svg_handle_tw for CSS fill-* and stroke-*

Controlled State Styling with .tw_state(...)

Section titled “Controlled State Styling with .tw_state(...)”

Pass an explicit IssNodeState when a state comes from your app model (such as form validation or selection).

use iced::widget::{button, text, text_input};
use iss::{tw, IssNodeState, TwExt};
let input = text_input("Email", &state.email)
.on_input(Message::EmailChanged)
.tw_state(
tw!("px-3 py-2 bg-zinc-900 border border-zinc-700 focus:border-violet-400 invalid:border-rose-500 rounded-lg"),
if state.email_valid { IssNodeState::EMPTY } else { IssNodeState::INVALID },
);
let save_btn = button(text("Save").tw(tw!("text-sm font-medium text-white")))
.on_press(Message::Save)
.tw(tw!("px-4 py-2 bg-violet-600 hover:bg-violet-500 active:bg-violet-700 rounded-lg cursor-pointer"));

Multi-Child Layouts: row_tw, col_tw, flex_tw, grid_tw

Section titled “Multi-Child Layouts: row_tw, col_tw, flex_tw, grid_tw”

Iced keeps the children inside Row and Column private, so ISS provides layout helpers that handle gap-*, justify-*, items-*, wrapping, 2D grids, divide-*, and structural child selectors (first:*, odd:*, peer-*).

use iced::widget::{button, container, text};
use iss::{col_tw, flex_tw, grid_tw, row_tw, tw, TwExt};
// Horizontal toolbar with spaced actions
let toolbar = row_tw(
[
text("Releases").tw(tw!("text-base font-semibold text-white")),
button(text("New").tw(tw!("text-xs font-semibold text-white")))
.on_press(Message::NewRelease)
.tw(tw!("px-3 py-1.5 bg-violet-600 hover:bg-violet-500 rounded-lg cursor-pointer")),
],
tw!("w-full items-center justify-between gap-4"),
);
// Wrapping tag bar
let tags = flex_tw(
[
container(text("v0.2.0").tw(tw!("text-xs text-violet-200"))).tw(tw!("px-2.5 py-1 bg-violet-500/20 rounded-full")),
container(text("iced 0.14").tw(tw!("text-xs text-zinc-200"))).tw(tw!("px-2.5 py-1 bg-zinc-800 rounded-full")),
container(text("tailwind v4").tw(tw!("text-xs text-zinc-200"))).tw(tw!("px-2.5 py-1 bg-zinc-800 rounded-full")),
],
tw!("flex-row flex-wrap gap-2"),
);
// 2D grid with sidebar + fluid content track
let shell = grid_tw(
[
container(text("Sidebar").tw(tw!("text-sm text-zinc-300"))).tw(tw!("p-4 bg-zinc-900 rounded-xl")),
col_tw([toolbar, tags], tw!("p-4 gap-4 bg-zinc-900 rounded-xl")),
],
tw!("w-full grid-cols-[220px_1fr] gap-4"),
);

Other specialized multi-child helpers available in iss: stack_tw (layered absolute overlays and z-*), list_tw (list-disc / marker:*), table_tw (border-collapse), and columns_tw (multi-column flows).