Skip to content
OAIT Design System

Design system / Components

Snackbar

The family's only transient message: one short sentence at the bottom of the window that confirms what just happened, or says that a background action failed, and goes by itself.

When to use

  • Confirm, in the past tense, something the person just did: "Mobile number saved" with "Undo", then "Change undone" (D-CSN-25, D-BCP-20).
  • Say that a background action failed, with one way to retry: "We couldn’t change the language." with "Try again" (D-CSN-25).
  • Offer one quick follow-up that is not essential: "A new version is ready" with "Reload" (Global ID's app update).
  • After every one-field edit in settings: "{Field} saved" with "Undo" (forms and settings, canonical §11 row 6).

When not to use

Situation Use instead
A field is empty or wrong (validation) The field's error line, and the error summary for longer forms. Never a snackbar (D-CSN-25, D-CAI-10)
A blocking error, or anything the person must read before going on An error banner with role="alert" above the main button (canonical §10.4)
A question, a destructive confirmation, a choice A dialog or bottom sheet (canonical §10.19)
A notice that stays (demo data, a clock problem, a link problem) A banner or the page strip
Something is loading or being sent Words with a spinner, or skeleton blocks
A short "Copied" confirmation on the control itself The assist chip's label change for --duration-dwell-confirm (2400ms) in chips
A status that lasts ("Ready to scan", "Live now") A status indicator

Anatomy

  1. Host: role="status" aria-live="polite", one per page, mounted empty when the page loads, fixed at the bottom of the window (.oa-snackbar-host).
  2. Container: the bar on inverse-surface with a 1px outline edge and elevation-3 (.oa-snackbar).
  3. Message: one sentence, two lines at most (.oa-snackbar__message).
  4. Action (optional, one): a 48px text button, a verb (.oa-snackbar__action).
  5. Close button (always): a 48px icon button named "Close message" (.oa-snackbar__close).

No icon, no colored edge, no title, no second action (D-CSN-25).

Variants

Variant Use for Key tokens
Message only Confirmations that need no follow-up ("Preferred name saved", "Change undone") --color-inverse-surface, --color-inverse-on-surface, --duration-dwell-snackbar (6000ms)
With one action Reversible changes ("Undo"), retries ("Try again"), an update ("Reload") adds --color-inverse-primary for the action and --duration-dwell-snackbar-action (10000ms)

The snackbar looks the same in both themes: inverse-surface stays dark in the dark theme, and the 1px outline edge (5.85:1 against the dark page) separates the bar from it (D-ARC-08, canonical §2.6).

Sizes

One size.

Size Height Padding Type style Icon size
Default 56px at least (min-h-14); 58px with its 1px edge around the 48px buttons 4px, 16px at the inline start (py-1 ps-4 pe-1) message body-md; action label-md close icon 24px (--size-icon-lg)

The bar is as wide as the host allows, up to 600px (max-w-snackbar, --container-snackbar): the window minus 16px on each side below 768px, then at most 600px from the inline start (D-LAY-06, canonical §4.3).

Tokens

Part Property Token
Host layer --z-snackbar (60, z-60): above dialogs, so the feedback after a dialog is never hidden (D-ARC-26)
Host inline inset --space-4 (16px) below 768px; --space-6 (24px) from 768px; plus the side safe-area insets (--oa-safe-start, --oa-safe-end), so a landscape phone keeps the text out of the notch
Host bottom --space-4 + the bottom inset (--oa-safe-bottom, env(safe-area-inset-bottom) in Tailwind); above the navigation bar --space-24 (96px) + the inset; from 768px --space-6 + the inset; above other bottom chrome --oa-snackbar-host-offset + the inset
Bar fill and text --color-inverse-surface, --color-inverse-on-surface (11.63:1 light, 13.83:1 dark)
Bar edge 1px solid --color-outline
Bar corners --radius-12px (rounded-12px)
Bar shadow --shadow-elevation-3
Bar min height, max width --space-14 (56px), --container-snackbar (600px)
Bar padding, gap --space-1 (4px) block and inline end, --space-4 (16px) inline start; gap --space-1
Bar focus ring --color-focus-ring re-pointed to --color-inverse-primary on the bar (7.74:1)
Message type, padding --text-body-md and its companions; --space-2-5 (10px) block padding
Action label --color-inverse-primary (7.74:1 light, 9.21:1 dark), --text-label-md
Action box 48px tall (--size-touch-target), --space-3-5 (14px) inline padding, --radius-full
Close box 48 × 48px (--size-touch-target), --radius-full, --color-inverse-on-surface
Action, close state layer currentColor at --opacity-state-hover (0.08) and --opacity-state-pressed (0.12), fading over --duration-short-3 with --ease-standard, covering the 1px edge
Bar enter, exit opacity over --duration-short-3: --ease-emphasized in, --ease-emphasized-accelerate out (canonical §7.3)
Timer dwell --duration-dwell-snackbar (6000ms), --duration-dwell-snackbar-action (10000ms)

States

State What changes
Enabled The action label in inverse-primary, the close icon in inverse-on-surface, no layer.
Hover (pointer devices only) The action or close gets a layer of its own content color at --opacity-state-hover (8%), fading in over --duration-short-3.
Focus-visible The family ring (3px, 2px outside) in --color-inverse-primary, re-pointed on the bar, never per button. No focus layer (canonical §2.8, D-COL-20).
Pressed The layer at --opacity-state-pressed (12%) at once; it fades back on release.
Disabled Never: a snackbar action that cannot run is not shown.
Selected, error, loading Not used: nothing in the bar is selectable, a failure is the message itself ("We couldn’t change the language."), and the action closes the bar before its work starts, so the bar never shows a spinner.
Entering The bar fades in over --duration-short-3 (@starting-style); nothing slides or scales (D-SEM-16).
Leaving The script sets hidden; the bar fades out over --duration-short-3 with --ease-emphasized-accelerate, then the script removes it.
Reduced motion No fade: the bar appears and goes at once (canonical §7.7).

Behavior

  • One host per page. Mount .oa-snackbar-host once, empty, when the page loads, after the page content. A live region added later is not announced reliably, so the host is never created on demand (canonical §13, D-CSN-25).
  • One at a time. A new message replaces the one on screen; there is no queue and no stack (D-CSN-25).
  • Timing. The bar stays --duration-dwell-snackbar (6000ms), or --duration-dwell-snackbar-action (10000ms) when it has an action. The timer waits while a pointer is over the bar or focus is inside it, and starts again when both leave. JavaScript reads the durations from the tokens, never from literals (canonical §7.1, §13 consistency and timing).
  • Action. Pressing it closes the snackbar first, then acts, so the action can show its own message: "Undo" → "Change undone" (Global ID's SnackbarProvider).
  • Close. Dismisses the bar, which fades out as it does when its time is up. If focus was inside the bar, put it back where it was before (the control that caused the message, or <main>), so focus is never lost on the page. The sources do not say where focus goes; this rule follows WCAG 2.4.3 (focus order).
  • Placement. Below 768px the bar spans the window minus 16px gutters, 16px above the bottom edge and the safe-area inset. With the phone navigation bar add .oa-snackbar-host--nav-bar: calc(6rem + env(safe-area-inset-bottom)), 16px above the 80px bar. Above other bottom chrome (the sticky action bar, which shows below 1024px), set --oa-snackbar-host-offset on the host, while that bar shows, to the bar's height without its safe-area padding plus 16px; the host adds the inset itself. From 768px the bar sits 24px from the inline start and from the bottom (or above a sticky action bar that still shows), up to 600px wide (canonical §10.21, §10.29, §4.10).
  • Over an app shell. While a snackbar shows, the shell's scrolling <main> gains room at its end (--size-scroll-offset, 96px, plus the bottom inset where <main> meets the screen edge) and the same scroll padding, so the last control of the page can scroll clear of the bar and a focused control is never hidden under it (WCAG 2.4.11). The reference CSS does this by itself (:root:has(.oa-snackbar-host > .oa-snackbar:not([hidden])) .oa-app-shell__main); without it, the settings template's last link sat under a snackbar that stays 10 seconds.
  • Focus. Showing a snackbar never moves focus. Tab reaches the action and the close button; Enter and Space press them.
  • Print. The host is hidden in print.
  • Script contract (framework-free). show(message, action?) empties the host, appends one .oa-snackbar, starts the timer, and wires pointerenter, pointerleave, focusin, and focusout (with relatedTarget) to pause and restart it. dismiss() sets hidden on the bar and removes it after --duration-short-3; it never waits for transitionend (canonical §7.7).
// Read a duration token (in ms) from the stylesheet, never a literal (canonical §7.1).
// On the server there is no stylesheet: it returns undefined there, where no snackbar shows.
const tokenMs = (name) =>
  typeof document === "undefined"
    ? undefined
    : parseFloat(getComputedStyle(document.documentElement).getPropertyValue(name));
const dwell = (hasAction) => tokenMs(hasAction ? "--duration-dwell-snackbar-action" : "--duration-dwell-snackbar");

Sonner (shadcn/ui products)

Jobs keeps Sonner and restyles it to the snackbar (canonical §10.21, D-CSN-25):

<Toaster
  position={dir === "rtl" ? "bottom-right" : "bottom-left"}
  dir={dir}
  visibleToasts={1}
  closeButton
  duration={tokenMs("--duration-dwell-snackbar")}
  offset={24}
  mobileOffset={16}
  toastOptions={{
    unstyled: true,
    classNames: {
      toast: "oa-snackbar",
      title: "oa-snackbar__message",
      actionButton: "oa-snackbar__action",
      closeButton: "oa-snackbar__close",
    },
  }}
/>
  • Toasts with an action pass duration: tokenMs("--duration-dwell-snackbar-action") (10000ms). Canonical's literal 6000 and 10000 are these tokens. Render the toaster in a client component: tokenMs (above) reads the tokens in the browser and returns undefined during server rendering, where no toast shows.
  • Sonner positions are physical, so Arabic pages pass position="bottom-right" (the inline start in right-to-left) with dir="rtl". With a phone navigation bar pass mobileOffset={{ bottom: "calc(96px + env(safe-area-inset-bottom))" }}.
  • No icons: show messages with plain toast(message) or toast(message, { action }); if a typed call such as toast.success is unavoidable, pass icon: null.
  • Sonner removes the outline of its toasts; restore the family ring on the toast and its buttons, in inverse-primary.
  • Move Sonner's toaster from its very high z-index onto the ladder: html [data-sonner-toaster] { z-index: var(--z-snackbar); } (canonical §4.9). Sonner inserts its own styles at run time, so these overrides start with html to outrank them whatever the order.
  • Sonner slides each toast in from below with a 400ms transition, even when unstyled; the family snackbar only fades over --duration-short-3 and nothing slides (canonical §7.3, D-SEM-16): html [data-sonner-toast] { transform: none; transition: opacity var(--duration-short-3) var(--ease-emphasized); }.
  • Sonner sizes its toasts with its own --width variable (356px): pass style={{ "--width": "var(--container-snackbar)" }} to the toaster so the bar reaches 600px like the family's (max-w-snackbar).

Accessibility

  • Element and role. The host is role="status" aria-live="polite": the message is read when the screen reader is free, never interrupting. Never role="alert" on a snackbar; blocking errors belong in a banner (canonical §13).
  • Name. The close button is named "Close message" / "إغلاق الرسالة" / "Fermer le message"; the action's visible verb is its name.
  • Keyboard and focus. Focus stays where it was; Tab reaches the buttons; focus returns from the bar when it closes (see Behavior).
  • Timing. 6 seconds for a message, 10 seconds with an action, paused while hovered or focused (WCAG 2.2.1). An Undo that matters also has a second path: the field's history in settings, or the action again on its row (D-CSN-25).
  • Targets. Action and close are 48px tall; the close button is 48 × 48px.
  • Contrast. Message 11.63:1 (light) and 13.83:1 (dark); action 7.74:1 and 9.21:1; the ring 7.74:1 (inverse-primary); the edge 5.85:1 against the dark page.
  • Reduced motion. The bar appears and goes without a fade.
  • Forced colors. The 1px edge is drawn in the system color; the ring stays an outline.

RTL and languages

  • The host aligns to the inline start: bottom left in English and French, bottom right in Arabic. The action and close button sit at the inline end. Nothing else mirrors; the close glyph never mirrors (canonical §8.3).
  • Arabic action labels are verbal nouns: "تراجع" (Undo), "إعادة التحميل" (Reload); "إعادة المحاولة" (Try again) is in the glossary and waits for native review (canonical §12.3, D-BCP-22).
  • French runs longer: "Numéro de mobile enregistré" with "Défaire" fits at 360px; labels never wrap or truncate; the message wraps to a second line. Check every new message at 360px.
  • Latin values inside an Arabic message (an email, a number) sit in <bdi dir="ltr"> (canonical §14.2).

Content

  • Confirmations: object, then past participle, no full stop for a fragment: "Mobile number saved", "Address saved", "Change undone". Never "successfully" (D-BCP-20, canonical §12.4).
  • Failures: what happened, as a sentence with a full stop, then the action: "We couldn’t change the language." with "Try again".
  • Actions: one verb from the glossary, 1–2 words: "Undo", "Try again", "Reload". Never "OK", "Dismiss", or "Retry" (canonical §12.3).
  • One sentence, two lines at most; 8 words is the aim. No exclamation marks, no emoji, no "please".
English Arabic French
Mobile number saved · Undo تم حفظ رقم الهاتف · تراجع Numéro de mobile enregistré · Défaire †
Change undone تم التراجع عن التغيير Modification annulée
A new version is ready · Reload نسخة جديدة جاهزة · إعادة التحميل Une nouvelle version est disponible · Recharger
We couldn’t change the language. · Try again تعذّر تغيير اللغة. · إعادة المحاولة † Impossible de changer la langue. · Réessayer
Close message (the close button's name) إغلاق الرسالة Fermer le message

Every string ships in Global ID except "إعادة المحاولة", the glossary's "Try again" (Global ID's button says "حاول مرة أخرى" today). † marks the glossary strings that wait for native review (canonical §12.3); "Défaire" is one of them although Global ID ships it.

Do and don't

Do Don't
"Mobile number saved" with "Undo" after a one-field edit "Your mobile number was saved successfully."
Show field errors under the fields and focus the first one Put "Choose an answer to continue." in a snackbar (Tamakkan today)
Mount the empty host once at page load Create a live region when the message appears
Keep 6 and 10 seconds and pause on hover and focus Remove the message after 3 seconds (Tamakkan today)
Keep the bar dark with its outline edge in both themes Switch to a light bar in the dark theme, or add a colored start edge
Replace the bar when a new message arrives Stack or queue several snackbars
Lift the host above the navigation bar with .oa-snackbar-host--nav-bar Let the bar cover the navigation bar or the sticky action button

Code

HTML (reference CSS)

The host, mounted once and empty:

<div class="oa-snackbar-host" role="status" aria-live="polite"></div>

A bar, as the script renders it inside the host:

<div class="oa-snackbar">
  <p class="oa-snackbar__message">Mobile number saved</p>
  <button type="button" class="oa-snackbar__action">Undo</button>
  <button type="button" class="oa-snackbar__close" aria-label="Close message"><span class="oa-icon" aria-hidden="true" translate="no">close</span></button>
</div>

Arabic:

<div dir="rtl" lang="ar">
  <div class="oa-snackbar">
    <p class="oa-snackbar__message">تم حفظ رقم الهاتف</p>
    <button type="button" class="oa-snackbar__action">تراجع</button>
    <button type="button" class="oa-snackbar__close" aria-label="إغلاق الرسالة"><span class="oa-icon" aria-hidden="true" translate="no">close</span></button>
  </div>
</div>

Every variant and state is in reference/snippets/feedback.html; the CSS is reference/css/feedback.css.

Tailwind CSS v4

{/* Host: once per page, empty at load. Above a navigation bar use bottom-[calc(6rem+env(safe-area-inset-bottom))] instead of the bottom-[calc(1rem…)] value; above a sticky action bar (below 1024px) use the bar's height plus 1rem in the same calc. */}
<div
  role="status"
  aria-live="polite"
  className="pointer-events-none fixed inset-x-4 bottom-[calc(1rem+env(safe-area-inset-bottom))] z-60 flex md:inset-x-6 md:bottom-[calc(1.5rem+env(safe-area-inset-bottom))] print:hidden"
>
  <div className="pointer-events-auto flex min-h-14 w-full max-w-snackbar items-center gap-1 rounded-12px border border-outline bg-inverse-surface py-1 ps-4 pe-1 text-body-md text-inverse-on-surface shadow-elevation-3 transition-opacity duration-short-3 ease-emphasized starting:opacity-0 [--color-focus-ring:var(--color-inverse-primary)]">
    <p className="min-w-0 flex-1 py-2.5 wrap-anywhere text-pretty">Mobile number saved</p>
    <button
      type="button"
      className="relative isolate inline-flex h-12 shrink-0 items-center justify-center rounded-full border border-transparent px-3.5 text-label-md whitespace-nowrap text-inverse-primary before:absolute before:-inset-px before:-z-1 before:rounded-[inherit] before:bg-current before:opacity-0 before:transition-opacity before:duration-short-3 before:ease-standard hover:before:opacity-(--opacity-state-hover) active:before:opacity-(--opacity-state-pressed) active:before:transition-none"
    >
      Undo
    </button>
    <button
      type="button"
      aria-label="Close message"
      className="relative isolate inline-flex size-12 shrink-0 items-center justify-center rounded-full border border-transparent text-inverse-on-surface before:absolute before:-inset-px before:-z-1 before:rounded-[inherit] before:bg-current before:opacity-0 before:transition-opacity before:duration-short-3 before:ease-standard hover:before:opacity-(--opacity-state-hover) active:before:opacity-(--opacity-state-pressed) active:before:transition-none"
    >
      <Icon name="close" size={24} />
    </button>
  </div>
</div>

Tailwind's hover variant already applies only on devices that hover. The global ring in base CSS draws focus; [--color-focus-ring:…] re-points it on the bar.

React

The family's provider is Global ID's SnackbarProvider (src/components/ui/snackbar.tsx).

Prop Type Default Description
children ReactNode — The page below the provider. Put one provider near the root.
closeLabel string — The close button's name, translated: "Close message".
aboveNavigationBar boolean false Lifts the host above the phone navigation bar (.oa-snackbar-host--nav-bar).

useSnackbar() returns show(message: string, options?: { action?: { label: string; onClick: () => void } }). A call replaces the snackbar on screen; the dwell is 6000ms, or 10000ms with an action, read from the tokens.

const show = useSnackbar()

async function saveMobile(value: string) {
  const previous = await updateMobile(value)
  show(t("me.fields.mobile.saved"), {
    action: {
      label: t("me.actions.undo"),
      onClick: async () => {
        await updateMobile(previous)
        show(t("me.actions.undone"))
      },
    },
  })
}