The @realmorg/ui theme defines colour, spacing, type, radius, shadow and motion tokens as custom properties on :root. REALM UI components use them. Use them in your own components too, so sizes and colours match and theming works.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@realmorg/ui@alpha/dist/theme.css">
Custom properties inherit through shadow roots, so a token on :root reaches every component.
:host {
padding: calc(var(--spacing) * 4);
border-radius: var(--radius-md);
font-size: var(--text-sm);
box-shadow: var(--shadow-sm);
color: var(--card-foreground);
background: var(--card);
}
Each surface colour has a matching -foreground for text on it.
Colours are written in oklch(). The values differ between light and dark mode. See theme.css for the exact numbers.
theme.css also sets color-scheme and gives body the --background, --foreground and --font-sans values.
Previewindex.htmltoken-swatches.html
primary
secondary
muted
accent
destructive
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Design tokens demo</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@realmorg/realm@alpha/dist/realm.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@realmorg/ui@alpha/dist/theme.css">
<script type="module" src="https://cdn.jsdelivr.net/npm/@realmorg/realm@alpha/dist/realm.js"></script>
</head>
<body>
<import-element from="./token-swatches.html"></import-element>
<token-swatches></token-swatches>
</body>
</html>
<custom-element name="token-swatches">
<style>
:host {
display: flex;
flex-wrap: wrap;
gap: calc(var(--spacing) * 2);
}
span {
padding: calc(var(--spacing) * 2) calc(var(--spacing) * 3);
border-radius: var(--radius-md);
font-size: var(--text-sm);
box-shadow: var(--shadow-xs);
}
.primary { background: var(--primary); color: var(--primary-foreground); }
.secondary { background: var(--secondary); color: var(--secondary-foreground); }
.muted { background: var(--muted); color: var(--muted-foreground); }
.accent { background: var(--accent); color: var(--accent-foreground); }
.destructive { background: var(--destructive); color: var(--destructive-foreground); }
</style>
<span class="primary">primary</span>
<span class="secondary">secondary</span>
<span class="muted">muted</span>
<span class="accent">accent</span>
<span class="destructive">destructive</span>
</custom-element>
Edit this page on GitHub · View as Markdown