Skip to content

Get started

Theming

Components never read raw colours or shadows. They read semantic roles from one theme contract ("a raised surface", "the accent", "the press effect"), and every theme fills that contract in. Switching themes therefore never touches component code.

The contract

A theme has a feel, shared by both modes, and a light and dark mode.

Colour roles (per mode): bg, bgImage, bgSize, text, textMuted, onTint, border, accent, accentContrast, accentBorder, focusRing, success, warning, danger, and a six-colour palette for tags, avatars, charts and tinted cards.

Surfaces (per mode): three materials, raised (cards, buttons), inset (inputs, wells, tracks) and overlay (dialogs, popovers, toasts). Each has bg, bgSolid (the opaque fallback for reduced transparency), border, shadow (two layers at most), backdrop (blur: overlay only) and highlight (an effect layer under the content, used for glass shine, clay sheen and textures).

Effect (per mode): glow around accent controls.

Feel: radii (sm, md, lg, full, control), borderWidth, three font families (body, display, mono), fontWeightStrong, tintStrength, pressTransform, hoverTransform, duration and easing.

Every field becomes a CSS variable: --og-color-text, --og-surface-raised-shadow, --og-radius-control and so on. The live table below shows every value for the theme you pick.

Write your own theme

A theme is one TypeScript file. defineTheme type-checks it against the contract, so a missing field is a compile error.

ts
// packages/tokens/src/themes/paper.ts
import { defineTheme } from '../contract.js';
import { accent, accentContrast, fonts, noGlow, palettes, status } from '../shared.js';

export default defineTheme({
  name: 'paper',
  label: 'Paper',
  description: 'Cream paper, ink outlines, no shadows.',
  feel: {
    radius: { sm: '2px', md: '4px', lg: '6px', full: '9999px', control: '4px' },
    borderWidth: '1.5px',
    fontFamily: fonts.sans,
    fontFamilyDisplay: 'Georgia, serif',
    fontFamilyMono: fonts.mono,
    tintStrength: '18%',
    fontWeightStrong: '600',
    pressTransform: 'translateY(1px)',
    hoverTransform: 'none',
    duration: '120ms',
    easing: 'ease-out',
  },
  modes: {
    light: {
      color: {
        bg: '#fbf7ee', bgImage: 'none', bgSize: 'auto',
        text: '#1c1917', onTint: '#1c1917', textMuted: '#57534e',
        border: '#1c1917',
        accent: accent('#b45309'), accentContrast: accentContrast('#ffffff'),
        accentBorder: '#1c1917', focusRing: accent('#b45309'),
        ...status.light, palette: [...palettes.light],
      },
      effect: { glow: noGlow },
      surface: {
        raised:  { bg: '#fffdf8', bgSolid: '#fffdf8', border: '#1c1917', shadow: 'none', backdrop: 'none', highlight: 'none' },
        inset:   { bg: '#f5efe2', bgSolid: '#f5efe2', border: '#1c1917', shadow: 'none', backdrop: 'none', highlight: 'none' },
        overlay: { bg: '#fffdf8', bgSolid: '#fffdf8', border: '#1c1917', shadow: '4px 4px 0 #1c1917', backdrop: 'none', highlight: 'none' },
      },
    },
    dark: { /* the same shape with dark values */ },
  },
});

Then add it to src/themes/index.ts and run pnpm build. It's compiled to themes.css, to themes/paper.css on its own, and to JSON for other platforms.

Check it

bash
pnpm --filter @og-ui/tokens contrast   # WCAG 2.2 AA: text, muted text, accent, focus ring, surfaces, badges
pnpm test                              # axe in every theme and mode, plus keyboard tests
pnpm test:perf                         # theme-switch time, scroll FPS, hover cost on 3,000 components

Rules a theme must keep

  • focusRing has 3:1 contrast against bg; text pairs reach 4.5:1.
  • Shadows have two layers at most. They are the main paint cost.
  • Only overlay may blur (backdrop). Repeated elements fake glass with a translucent fill.
  • bgSolid must look right on bg: it replaces translucent fills when people ask for reduced transparency.
  • Motion is transform, opacity and colour only. OG UI turns hover and press motion off under prefers-reduced-motion.

Theme one section

Themes nest: any element with data-og-theme (and optionally data-og-mode) re-themes everything inside it. That's how this site shows each component in all seven themes on one page.

Every token, live

VariableClean SaaS, light
--og-color-bg#fafafa
--og-color-bg-imagenone
--og-color-bg-sizeauto
--og-color-text#0a0a0b
--og-color-on-tint#0a0a0b
--og-color-text-muted#62626d
--og-color-border#e4e4e7
--og-color-accentvar(--og-accent, #4f46e5)
--og-color-accent-contrastvar(--og-accent-contrast, #ffffff)
--og-color-accent-bordertransparent
--og-color-focus-ringvar(--og-accent, #4f46e5)
--og-color-success#15803d
--og-color-warning#b45309
--og-color-danger#b91c1c
--og-palette-1#2563eb
--og-palette-2#db2777
--og-palette-3#059669
--og-palette-4#d97706
--og-palette-5#7c3aed
--og-palette-6#0891b2
--og-effect-glow0 0 0 transparent
--og-surface-raised-bg#ffffff
--og-surface-raised-bg-solid#ffffff
--og-surface-raised-border#e4e4e7
--og-surface-raised-shadow0 1px 2px rgba(10, 10, 11, 0.05)
--og-surface-raised-backdropnone
--og-surface-raised-highlightnone
--og-surface-inset-bg#ffffff
--og-surface-inset-bg-solid#ffffff
--og-surface-inset-border#d4d4d8
--og-surface-inset-shadowinset 0 1px 1px rgba(10, 10, 11, 0.04)
--og-surface-inset-backdropnone
--og-surface-inset-highlightnone
--og-surface-overlay-bg#ffffff
--og-surface-overlay-bg-solid#ffffff
--og-surface-overlay-border#e4e4e7
--og-surface-overlay-shadow0 12px 32px -12px rgba(10, 10, 11, 0.22), 0 2px 6px rgba(10, 10, 11, 0.06)
--og-surface-overlay-backdropnone
--og-surface-overlay-highlightnone
--og-radius-sm6px
--og-radius-md8px
--og-radius-lg12px
--og-radius-full9999px
--og-radius-control8px
--og-border-width1px
--og-fontInter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif
--og-font-displayInter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif
--og-font-mono"Geist Mono", "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace
--og-font-weight-strong500
--og-tint-strength14%
--og-presstranslateY(1px)
--og-hovernone
--og-duration150ms
--og-easingcubic-bezier(0.2, 0, 0, 1)