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:

  1. The SDK's web/soda.css: Tailwind, every token's default, base styles, and Soda's controls.
  2. 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.

TokenSetsUtilities
--color-pageThe pagebg-page
--color-surfaceCards, sheets, Soda's screensbg-surface
--color-subtleQuieter fills: hovered rows, wells, chipsbg-subtle
--color-scrimBehind a sheetbg-scrim
--color-ink, --color-mutedText, quieter texttext-ink, text-muted
--color-line, --color-line-strongBorders and rulesborder-line, divide-line
--color-accent, --color-accent-inkThe action color, and text on itbg-accent, text-accent-ink
--color-focusFocus rings (defaults to the accent)outline-focus, ring-focus
--color-danger, --color-danger-inkDestructive actions, errorsbg-danger, text-danger
--color-warn, --color-warn-inkWarningsbg-warn, text-warn-ink
--color-alert, --color-alert-inkAlertsbg-alert, text-alert-ink
--color-okDone, savedtext-ok
--font-sans, --font-display, --font-monoText, headings, code (default: Soda Sans, a subset of Mona Sans)font-sans, …
--text-uiText size on Soda's screenstext-ui
--radius-tag, -control, -card, -sheet, -pillCorners, small to roundrounded-control, …
--shadow-raised, --shadow-overlayLifted, floatingshadow-raised, …
--container-contentWidth of your view under Soda's barmax-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 */
@theme {
  --color-accent: light-dark(oklch(0.58 0.17 45), oklch(0.78 0.13 55));
  --font-sans: "Atkinson Hyperlegible Next", ui-sans-serif, sans-serif;
  --radius-control: 999px;
}

That changes every button, field, sheet and screen.

  • Fonts: put the files in web/fonts/, their @font-face in app.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:

@theme { --history-lightness-day: 0.52; --history-lightness-night: 0.72; }
@layer base {
  :root { --history-lightness: var(--history-lightness-day); }
  @media (prefers-color-scheme: dark) { :root { --history-lightness: var(--history-lightness-night); } }
}

Classes in views#

view! {
    <li class="item flex items-start gap-3 rounded-control px-3 py-2"
        class:opacity-60=item.done class:bg-accent/10=selected class=extra>…</li>
}
FormDoes
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=condAdds name when cond is true; class:name alone always adds it. Any class works: class:aria-[current=page]:font-bold
class=exprClasses 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 .grow rule would style every grow utility. 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-4 then px-6: px-6 wins.
  • px-6 then p-4: p-4 wins (a shorthand covers its longhands).
  • p-4 then px-6: both stay (px-6 sets 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!("soda-btn", "soda-btn-primary" => primary, "opacity-50" => busy)) { "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.

ClassFor
soda-btn + -primary, -quiet, -danger, -smButtons
soda-inputFields, textareas, selects (red when an action rejects the value)
soda-field, soda-label, soda-hint, soda-errorA labelled field
soda-card, soda-chipA bordered surface, a small label
soda-tabs (soda-tabs-pills), soda-tabTabs; the current one has aria-current="page"
soda-menu, soda-menu-item, soda-menu-labelMenus; the item in use has aria-current="true"
soda-empty, soda-empty-titleAn empty list
soda-avatarInitials 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:

import { component } from '/soda-component.js'

component('pantry-expiry', {
  props: ({ number }) => ({ at: number }),
  parts: ['badge'],
  render: ({ html, props, part }) => html`
    <span class="${part('badge', 'inline-flex gap-1.5 rounded-pill bg-subtle px-2.5 text-sm')}">
      <soda-time at="${props.at}" format="ago"></soda-time>
    </span>`,
})
<pantry-expiry at="…" badge-class="bg-warn text-warn-ink"></pantry-expiry>
  • 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 by cn.
  • Prefix its name with your app's (pantry-…), never soda-.

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:

soda-bar::part(button primary) { @apply rounded-pill px-5; }

The parts Soda's screens export:

WhereParts
Buttonsbutton, with primary, quiet, danger, share, security, undo
Formsform, field, label, input, error
Texttitle, heading, brand, code
Noticesnotices, notice with warn or alert, toast (toast error)
Sheetssheet, panel, head, heading, close, body, backdrop, details, summary
The barbar, person, status, menu
Sign-in and startgate, 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:

::view-transition-old(root),
::view-transition-new(root) { animation-duration: 180ms; }

/* The heading glides to its place on the next page instead of fading. */
.page-title { view-transition-name: page-title; }

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.js and /kit.js with blocking="render".
  • A local-first shell loads /soda-whole.js (async blocking="render"), then /soda-local.js and /kit.js (blocking="render"). The service worker answers /soda-whole.js once 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, then data-settled two 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), in web/*.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:

WasNow
--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.

Esc