Design Tokens
Axiom uses CSS variables to declare design tokens and also conveniently exports the variable names in the theme object.
#
Declaring tokens
#
#
CSS variables
#
Every token listed under Reference is available as a CSS variable under the --ax-* prefix. Spacing is not a token: see Spacing.
So given a tokens object like this:
{
"colors": {
"bg.accent": "#abff44",
"fg.success": "#03a65d"
},
"zIndex": {
"popover": "3000"
}
}The following css custom properties will be available:
:root {
--ax-colors-bg-accent: #abff44;
--ax-colors-fg-success: #03a65d;
--ax-zIndex-popover: 3000;
}And they can also be accessed via the theme object:
import { theme } from "@optiaxiom/react";
console.log(theme.colors["bg.accent"] === "var(--ax-colors-bg-accent)"); // true
console.log(theme.colors["fg.success"] === "var(--ax-colors-fg-success)"); // true
console.log(theme.zIndex.popover === "var(--ax-zIndex-popover)"); // true#
Spacing
#
Spacing values (gap, p*, m*) exist only as style props. There is no --ax-space-* variable and no theme entry for them.
Each value is a pixel count: gap="8" is 8px, p="24" is 24px. Use the style prop wherever you render the element. When you style markup you don’t render, such as rendered markdown or a third-party widget, write the same pixel value.
#
Sizing scale
#
Sizes, spacing, font sizes, and radii are based on rem, so they follow the root font size of the page, including the user’s browser font size setting.
If you embed Axiom in pages you don’t control (for example an overlay inside a shadow root on third-party sites), set --ax-styles-scale to control the size of 1rem for Axiom. Using max() keeps components from shrinking on pages that reduce the root font size, while still growing when the user increases their browser font size:
:host {
--ax-styles-scale: max(1rem, 16px);
}Set it on the same element the theme is declared on: :root, or :host inside a shadow root. Breakpoints always follow the browser default font size and are not affected.
#
Consuming tokens
#
#
Using style props
#
For all react components you can use the various style props to set the styles using tokens.
import { Box } from "@optiaxiom/react";
export function App() {
return (
<Box bg="bg.success.subtle" color="fg.success.strong" p="16">
Using component props
</Box>
);
}#
Consuming variables from CSS
#
You can also directly use the CSS variable name in your .css files. Nothing checks these names, and a misspelled variable silently falls back to its default, so copy names from the Reference below or prefer the theme object.
App.tsx
import styles from "./App.module.css";
export function App() {
return <div className={styles.root}>Using CSS variables</div>;
}#
Consuming variables from JS
#
Axiom exports a theme contract that contains a map of all tokens to the corresponding CSS custom property name.
Use this theme object in any CSS-in-JS solution, such as vanilla-extract .css.ts files, instead of writing var(--ax-…) by hand: TypeScript rejects a token name that doesn’t exist.
import { theme } from "@optiaxiom/react";
export function App() {
return (
<div
style={{
background: theme.colors["bg.success.subtle"],
color: theme.colors["fg.success.strong"],
padding: "16px",
}}
>
Using inline styles
</div>
);
}#
Raw token values
#
Where Axiom’s CSS variables aren’t loaded, such as a stylesheet built as a string for an iframe, import the raw values from tokens instead of copying them, so they follow token updates.
import { tokens } from "@optiaxiom/react";
const stylesheet = `body { font-family: ${tokens.fontFamily.sans}; }`;Color values are light-dark() CSS strings, so they work only in CSS.
#
Reference
#
#
borderRadius
#
Name | Styles |
|---|---|
xs | var(--ax-borderRadius-xs) |
sm | var(--ax-borderRadius-sm) |
md | var(--ax-borderRadius-md) |
lg | var(--ax-borderRadius-lg) |
xl | var(--ax-borderRadius-xl) |
full | var(--ax-borderRadius-full) |
#
boxShadow
#
Name | Styles |
|---|---|
sm | var(--ax-boxShadow-sm) |
md | var(--ax-boxShadow-md) |
lg | var(--ax-boxShadow-lg) |
xl | var(--ax-boxShadow-xl) |
#
colors
#
Name | Styles |
|---|---|
bg.accent | var(--ax-colors-bg-accent) |
bg.accent.hovered | var(--ax-colors-bg-accent-hovered) |
bg.accent.light | var(--ax-colors-bg-accent-light) |
bg.accent.pressed | var(--ax-colors-bg-accent-pressed) |
bg.accent.subtle | var(--ax-colors-bg-accent-subtle) |
bg.avatar.neutral | var(--ax-colors-bg-avatar-neutral) |
bg.avatar.purple | var(--ax-colors-bg-avatar-purple) |
bg.default | var(--ax-colors-bg-default) |
bg.default.hovered | var(--ax-colors-bg-default-hovered) |
bg.default.inverse | var(--ax-colors-bg-default-inverse) |
bg.default.inverse.hovered | var(--ax-colors-bg-default-inverse-hovered) |
bg.default.inverse.pressed | var(--ax-colors-bg-default-inverse-pressed) |
bg.default.pressed | var(--ax-colors-bg-default-pressed) |
bg.error | var(--ax-colors-bg-error) |
bg.error.hovered | var(--ax-colors-bg-error-hovered) |
bg.error.light | var(--ax-colors-bg-error-light) |
bg.error.pressed | var(--ax-colors-bg-error-pressed) |
bg.error.subtle | var(--ax-colors-bg-error-subtle) |
bg.error.subtlest | var(--ax-colors-bg-error-subtlest) |
bg.information | var(--ax-colors-bg-information) |
bg.information.light | var(--ax-colors-bg-information-light) |
bg.information.subtle | var(--ax-colors-bg-information-subtle) |
bg.message.neutral | var(--ax-colors-bg-message-neutral) |
bg.overlay | var(--ax-colors-bg-overlay) |
bg.page | var(--ax-colors-bg-page) |
bg.pill.default | var(--ax-colors-bg-pill-default) |
bg.pill.hovered | var(--ax-colors-bg-pill-hovered) |
bg.secondary | var(--ax-colors-bg-secondary) |
bg.secondary.hovered | var(--ax-colors-bg-secondary-hovered) |
bg.spinner.default | var(--ax-colors-bg-spinner-default) |
bg.spinner.inverse | var(--ax-colors-bg-spinner-inverse) |
bg.success | var(--ax-colors-bg-success) |
bg.success.hovered | var(--ax-colors-bg-success-hovered) |
bg.success.light | var(--ax-colors-bg-success-light) |
bg.success.subtle | var(--ax-colors-bg-success-subtle) |
bg.tertiary | var(--ax-colors-bg-tertiary) |
bg.tertiary.hovered | var(--ax-colors-bg-tertiary-hovered) |
bg.warning | var(--ax-colors-bg-warning) |
bg.warning.hovered | var(--ax-colors-bg-warning-hovered) |
bg.warning.light | var(--ax-colors-bg-warning-light) |
bg.warning.subtle | var(--ax-colors-bg-warning-subtle) |
border.accent | var(--ax-colors-border-accent) |
border.control | var(--ax-colors-border-control) |
border.control.hovered | var(--ax-colors-border-control-hovered) |
border.default | var(--ax-colors-border-default) |
border.disabled | var(--ax-colors-border-disabled) |
border.error | var(--ax-colors-border-error) |
border.focus | var(--ax-colors-border-focus) |
border.focus.error | var(--ax-colors-border-focus-error) |
border.secondary | var(--ax-colors-border-secondary) |
border.success | var(--ax-colors-border-success) |
border.tertiary | var(--ax-colors-border-tertiary) |
border.warning | var(--ax-colors-border-warning) |
fg.accent | var(--ax-colors-fg-accent) |
fg.accent.hovered | var(--ax-colors-fg-accent-hovered) |
fg.accent.strong | var(--ax-colors-fg-accent-strong) |
fg.avatar.neutral | var(--ax-colors-fg-avatar-neutral) |
fg.avatar.purple | var(--ax-colors-fg-avatar-purple) |
fg.black | var(--ax-colors-fg-black) |
fg.default | var(--ax-colors-fg-default) |
fg.default.inverse | var(--ax-colors-fg-default-inverse) |
fg.disabled | var(--ax-colors-fg-disabled) |
fg.error | var(--ax-colors-fg-error) |
fg.error.hovered | var(--ax-colors-fg-error-hovered) |
fg.error.light | var(--ax-colors-fg-error-light) |
fg.error.strong | var(--ax-colors-fg-error-strong) |
fg.information | var(--ax-colors-fg-information) |
fg.information.light | var(--ax-colors-fg-information-light) |
fg.information.strong | var(--ax-colors-fg-information-strong) |
fg.link.default | var(--ax-colors-fg-link-default) |
fg.link.default.hovered | var(--ax-colors-fg-link-default-hovered) |
fg.link.inverse | var(--ax-colors-fg-link-inverse) |
fg.link.subtle | var(--ax-colors-fg-link-subtle) |
fg.link.visited | var(--ax-colors-fg-link-visited) |
fg.secondary | var(--ax-colors-fg-secondary) |
fg.spinner.default | var(--ax-colors-fg-spinner-default) |
fg.spinner.inverse | var(--ax-colors-fg-spinner-inverse) |
fg.success | var(--ax-colors-fg-success) |
fg.success.hovered | var(--ax-colors-fg-success-hovered) |
fg.success.light | var(--ax-colors-fg-success-light) |
fg.success.strong | var(--ax-colors-fg-success-strong) |
fg.tertiary | var(--ax-colors-fg-tertiary) |
fg.warning | var(--ax-colors-fg-warning) |
fg.warning.hovered | var(--ax-colors-fg-warning-hovered) |
fg.warning.inverse | var(--ax-colors-fg-warning-inverse) |
fg.warning.light | var(--ax-colors-fg-warning-light) |
fg.warning.strong | var(--ax-colors-fg-warning-strong) |
fg.white | var(--ax-colors-fg-white) |
#
duration
#
Name | Styles |
|---|---|
sm | var(--ax-duration-sm) |
md | var(--ax-duration-md) |
lg | var(--ax-duration-lg) |
#
fontFamily
#
Name | Styles |
|---|---|
heading | var(--ax-fontFamily-heading) |
mono | var(--ax-fontFamily-mono) |
sans | var(--ax-fontFamily-sans) |
#
fontSize
#
Name | Styles |
|---|---|
xs | fontSize: var(--ax-fontSize-xs-fontSize);lineHeight: var(--ax-fontSize-xs-lineHeight); |
sm | fontSize: var(--ax-fontSize-sm-fontSize);lineHeight: var(--ax-fontSize-sm-lineHeight); |
md | fontSize: var(--ax-fontSize-md-fontSize);lineHeight: var(--ax-fontSize-md-lineHeight); |
lg | fontSize: var(--ax-fontSize-lg-fontSize);lineHeight: var(--ax-fontSize-lg-lineHeight); |
xl | fontSize: var(--ax-fontSize-xl-fontSize);lineHeight: var(--ax-fontSize-xl-lineHeight); |
2xl | fontSize: var(--ax-fontSize-2xl-fontSize);lineHeight: var(--ax-fontSize-2xl-lineHeight); |
3xl | fontSize: var(--ax-fontSize-3xl-fontSize);lineHeight: var(--ax-fontSize-3xl-lineHeight); |
4xl | fontSize: var(--ax-fontSize-4xl-fontSize);lineHeight: var(--ax-fontSize-4xl-lineHeight); |
#
maxSize
#
Name | Styles |
|---|---|
xs | var(--ax-maxSize-xs) |
sm | var(--ax-maxSize-sm) |
md | var(--ax-maxSize-md) |
lg | var(--ax-maxSize-lg) |
#
size
#
Name | Styles |
|---|---|
2xs | var(--ax-size-2xs) |
xs | var(--ax-size-xs) |
sm | var(--ax-size-sm) |
md | var(--ax-size-md) |
lg | var(--ax-size-lg) |
xl | var(--ax-size-xl) |
3xl | var(--ax-size-3xl) |
#
zIndex
#
Name | Styles |
|---|---|
popover | var(--ax-zIndex-popover) |
toast | var(--ax-zIndex-toast) |
tooltip | var(--ax-zIndex-tooltip) |
#
Related
#
Colors
Every text, background, and border color token, with light and dark mode values.
A
a
Typography
The type scale, and which component renders each style. Start here before reaching for font props.
Style Props
Set an element's styles directly with utility props, backed by our design tokens.