Styling
An app has one stylesheet, /app.css, and its look is set by the design tokens in web/app.css.
Change a token and everything follows: your views and Soda's own screens (sign-in, sharing, the
bar). Nothing else may set a color, font, radius or shadow. The build refuses it.
How the stylesheet is built#
scripts/build.sh compiles it with Tailwind CSS v4 (the standalone CLI, pinned in
scripts/tailwind.sh; no Node), in this order:
- The SDK's
web/soda.css: Tailwind, every token's default, base styles, and Soda's controls. - Your
web/app.css: your tokens, and anything you add.
Tailwind reads your Rust (src/) and web/ for the classes you use. The result is
dist/app.css, which the shell links. A local-first build adds the link to a shell that's missing
it; a server or static shell must have it. Then the token check runs.
Tokens#
Tailwind's own palette, fonts, radii and shadows are removed: bg-blue-500 doesn't exist. Each
token is a CSS variable and a family of utilities. Colors are light-dark() pairs, so one value
covers both schemes.
| Token | Sets | Utilities |
|---|---|---|
--color-page | The page | bg-page |
--color-surface | Cards, sheets, Soda's screens | bg-surface |
--color-subtle | Quieter fills: hovered rows, wells, chips | bg-subtle |
--color-scrim | Behind a sheet | bg-scrim |
--color-ink, --color-muted | Text, quieter text | text-ink, text-muted |
--color-line, --color-line-strong | Borders and rules | border-line, divide-line |
--color-accent, --color-accent-ink | The action color, and text on it | bg-accent, text-accent-ink |
--color-focus | Focus rings (defaults to the accent) | outline-focus, ring-focus |
--color-danger, --color-danger-ink | Destructive actions, errors | bg-danger, text-danger |
--color-warn, --color-warn-ink | Warnings | bg-warn, text-warn-ink |
--color-alert, --color-alert-ink | Alerts | bg-alert, text-alert-ink |
--color-ok | Done, saved | text-ok |
--font-sans, --font-display, --font-mono | Text, headings, code (default: Soda Sans, a subset of Mona Sans) | font-sans, … |
--text-ui | Text size on Soda's screens | text-ui |
--radius-tag, -control, -card, -sheet, -pill | Corners, small to round | rounded-control, … |
--shadow-raised, --shadow-overlay | Lifted, floating | shadow-raised, … |
--container-content | Width of your view under Soda's bar | max-w-content |
Soda's components have their own tokens, each defaulting to the ones above:
--color-bar,--color-status,--color-status-ink,--color-toast,--color-toast-ink--color-countdown-soon,-over,-met--color-history-ink,-stop,-train,--history-lightness,--history-chroma,--ease-history--person-lightness,--person-chroma,--color-person-ink(each person's color)--landed(the animation a moved card plays)
Add your own the same way: --color-dose-given in @theme gives you bg-dose-given.
Restyle an app#
/* web/app.css */
@}That changes every button, field, sheet and screen.
- Fonts: put the files in
web/fonts/, their@font-faceinapp.css, and the license beside them. A subset of an SIL OFL font is a modified version: if the license reserves the name (Mona Sans reserves "Mona"), rename it, and keep the copyright notice. - Tokens named at runtime: Tailwind drops tokens no utility uses. If code builds a name
(
var(--color-pill-{slug})), declare those tokens in@theme static.
Light and dark#
light-dark() takes colors only. For any other value that differs by scheme, declare two tokens
and pick one outside @theme:
@ }
@ }
{ } }
}Classes in views#
view! | Form | Does |
|---|---|
class="…" | Literal classes. Put the element's hook here too (item: one word that tests and browser code find it by, never styled) |
class:name=cond | Adds name when cond is true; class:name alone always adds it. Any class works: class:aria-[current=page]:font-bold |
class=expr | Classes from a value: a component's class prop, or a const |
However many forms you use, the element gets one class attribute.
- Write every class whole. Tailwind finds classes by reading the source, so
format!("bg-{c}")never reaches the stylesheet. - Arbitrary values are fine for sizes (
p-[13px]), weights (font-[520]) and shadows built from tokens (shadow-[0_-1px_0_var(--color-line)]). Never for colors, font families or radii. - Name your own CSS classes for what they are, never like a utility. A
.growrule would style everygrowutility. The check refuses it. - A char literal holding
"('"') breaks Tailwind's scanner for the rest of the file. Write'\u{22}'.
Classes given to a component win#
<Button class="rounded-pill px-6"> overrides the component's own classes wherever they set the
same property, whatever order Tailwind wrote them in. cn drops a class when a later one, under
the same variant, sets everything it sets:
px-4thenpx-6:px-6wins.px-6thenp-4:p-4wins (a shorthand covers its longhands).p-4thenpx-6: both stay (px-6sets less).- A class the stylesheet doesn't have (a hook) always stays.
The build reads what each utility sets from your compiled stylesheet (app.classes.json), so this
holds for your own tokens and utilities too. Rust's soda::cn and the browser's cn use the same
map.
maud views#
Local-first apps written in maud put the hook bare and the utilities quoted, in one attribute:
li.task."flex items-start gap-3 rounded-control px-3 py-2 hover:bg-subtle"
button.save. soda_local::cx! keeps the classes whose condition holds. Never write .task and class="…" on
one element: that's two class attributes, and browsers keep only the first.
Soda's controls#
Soda's controls are soda-* classes in the components layer, built on the tokens. A utility beside
one always wins: class="soda-btn soda-btn-primary rounded-pill". Soda's components use them (a
<Button> is a soda-btn); use them directly on markup no component draws, like a link styled as
a button.
| Class | For |
|---|---|
soda-btn + -primary, -quiet, -danger, -sm | Buttons |
soda-input | Fields, textareas, selects (red when an action rejects the value) |
soda-field, soda-label, soda-hint, soda-error | A labelled field |
soda-card, soda-chip | A bordered surface, a small label |
soda-tabs (soda-tabs-pills), soda-tab | Tabs; the current one has aria-current="page" |
soda-menu, soda-menu-item, soda-menu-label | Menus; the item in use has aria-current="true" |
soda-empty, soda-empty-title | An empty list |
soda-avatar | Initials in a person's color |
Inside an element with data-hue (from soda::ui::hue), bg-person, text-person and
border-person use that person's color.
Browser components#
Code that must run in the page is a Rocket component in web/components/, written with Soda's
component. Each file there loads itself:
- Its shadow root shares your stylesheet (one parsed copy for every component,
app.styles.js). Tokens inherit into it, so a token set on a section holds inside its components. - Each named part takes classes from outside as
name-class="…", merged after its own bycn. - Prefix its name with your app's (
pantry-…), neversoda-.
Soda's own components#
Soda's screens (soda-ui.js: the gate, bar, notices, sharing, security, toasts, soda-dialog) and
elements (soda-elements.js: soda-time, soda-countdown, soda-lists, …) render in shadow DOM
and read the tokens, so tokens restyle them. To style one piece, target its part:
) }The parts Soda's screens export:
| Where | Parts |
|---|---|
| Buttons | button, with primary, quiet, danger, share, security, undo |
| Forms | form, field, label, input, error |
| Text | title, heading, brand, code |
| Notices | notices, notice with warn or alert, toast (toast error) |
| Sheets | sheet, panel, head, heading, close, body, backdrop, details, summary |
| The bar | bar, person, status, menu |
| Sign-in and start | gate, start, main, aside, steps, create, yours, returning, choice |
For anything else, soda.theme(css) in web/kit.js, or a <style id="soda-theme"> in the shell,
adds rules inside every component, after their own.
Page transitions#
Moving to another page is a view transition (the browser's crossfade). Moving within a page (a tab, a filter) is instant, and so is every move when the reader turns motion down. Restyle it with the View Transitions pseudo-elements:
),
) }
/* The heading glides to its place on the next page instead of fading. */
}Reloads paint whole#
A reload goes from the last frame straight to the finished page: nothing pops in or replays its entrance.
- A server or static shell loads
/soda.jsand/kit.jswithblocking="render". - A local-first shell loads
/soda-whole.js(async blocking="render"), then/soda-local.jsand/kit.js(blocking="render"). The service worker answers/soda-whole.jsonce the page is whole, holding the last frame for at most half a second. The build warns about a local-first shell without it. - Soda's script sets
<html data-drawn>once components and fonts are in, thendata-settledtwo frames later. Until then, transitions and animations finish instantly, so entrances (starting:,animate-*) only play for what arrives later: a new card, a toast. - Anything that affects layout belongs in the view, not in browser code that runs after the page connects.
The token check#
scripts/tokens.mjs runs after the stylesheet compiles and fails the build, with file and line,
on:
- a raw color, font family, radius or shadow outside
@theme(or@font-face), inweb/*.css, in CSS your browser code writes, or in inline styles; - a bracketed value carrying one:
bg-[#ff0000],rounded-[7px],font-[Georgia]; - a utility the stylesheet doesn't have: a removed default (
bg-blue-500) or a typo (text-mutd); - a CSS class named like a utility (
.block,.grow).
To allow one line, add a comment saying tokens: allow and why (say, a print style on white
paper). SODA_TOKENS=report lists everything without failing, for an app moving onto tokens.
Old names#
Soda's components still honor the --soda-* properties apps set before tokens, ahead of the
tokens. Move each to its token:
| Was | Now |
|---|---|
--soda-bg, --soda-surface, --soda-page | --color-surface, --color-subtle, --color-page |
--soda-ink, -muted, -line | --color-ink, -muted, -line |
--soda-accent, -accent-ink, -focus | --color-accent, -accent-ink, -focus |
--soda-danger(-ink), -warn(-ink), -alert(-ink), -ok | --color-danger(-ink), … |
--soda-font, -mono, -size | --font-sans, --font-mono, --text-ui |
--soda-radius, -shadow | --radius-control, --shadow-overlay |
--soda-bar-bg, -status-bg, -status-ink | --color-bar, --color-status, --color-status-ink |
--soda-toast-bg, -toast-ink | --color-toast, --color-toast-ink |
--soda-countdown-soon, -over, -met | --color-countdown-soon, -over, -met |
--soda-history-ink, -stop, -train, -line-l, -line-c, -travel | --color-history-ink, -stop, -train, --history-lightness, --history-chroma, --ease-history |
--soda-landed | --landed |
This page is docs/styling.md in the SDK, built into this site as it is.