Customization

Variables

A guide to using variables to implement design tokens.

Overview

Variable NameValueNamespace
full"100%"-
fit"fit-content"-
max"max-content"-
min"min-content"-
font-family-sans"\"Inter\", $font-family-sans-fallback"font-family
font-family-sans-fallback"ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'"font-family
font-family-serif-fallback"ui-serif, Georgia, Cambria, 'Times New Roman', Times, serif"font-family
font-family-mono-fallback"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace"font-family
letter-spacing-tightest"-0.072em"letter-spacing
letter-spacing-tighter"-0.04em"letter-spacing
letter-spacing-tight"-0.02em"letter-spacing
letter-spacing-normal"0"letter-spacing
letter-spacing-wide"0.02em"letter-spacing
letter-spacing-wider"0.04em"letter-spacing
letter-spacing-widest"0.12em"letter-spacing
line-height-xs1.2line-height
line-height-sm1.4line-height
line-height-md1.6line-height
line-height-lg1.8line-height
line-height-xl2line-height
font-weight-thin100font-weight
font-weight-extralight200font-weight
font-weight-light300font-weight
font-weight-regular400font-weight
font-weight-medium500font-weight
font-weight-semibold600font-weight
font-weight-bold700font-weight
font-weight-extrabold800font-weight
font-weight-heavy900font-weight
font-size-3xs8font-size
font-size-2xs10font-size
font-size-xs12font-size
font-size-sm14font-size
font-size-md16font-size
font-size-lg18font-size
font-size-xl20font-size
font-size-2xl24font-size
font-size-3xl32font-size
font-size-4xl36font-size
font-size-5xl40font-size
font-size-6xl48font-size
font-size-7xl60font-size
font-size-8xl72font-size
font-size-9xl96font-size
font-size-10xl128font-size
border-radius-xs2border-radius
border-radius-sm4border-radius
border-radius-md6border-radius
border-radius-lg8border-radius
border-radius-xl12border-radius
border-radius-2xl16border-radius
border-radius-3xl24border-radius
border-radius-4xl32border-radius
order-first-999999order
order-last999999order
spacing-4xs2spacing
spacing-3xs4spacing
spacing-2xs6spacing
spacing-xs8spacing
spacing-sm12spacing
spacing-md16spacing
spacing-lg24spacing
spacing-xl32spacing
spacing-2xl48spacing
spacing-3xl64spacing
spacing-4xl96spacing
spacing-5xl128spacing
color-current"currentColor"color
font-family-serif"ui-serif, Georgia, Cambria, 'Times New Roman', Times, serif"font-family
font-family-mono"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace"font-family
screen-4xs360screen
screen-3xs480screen
screen-2xs600screen
screen-xs768screen
screen-sm834screen
screen-md1024screen
screen-lg1280screen
screen-xl1440screen
screen-2xl1600screen
screen-3xl1920screen
screen-4xl2560screen

In Master CSS, variables are used to manage tokens in the design system, such as colors, font families, etc., even based on different theme modes.

import { variables } from '@master/css'export default {    variables: {        spacing: { sm: 10 },        primary: '#000000'    }}

Apply custom variables using ambiguous shorthand:

<div class="font:sans max-w:screen-desktop m:sm bg:primary">…</div>

Add a string variable

Create a string variable to reuse it in your markup.

export default {    variables: {        content: {             hash: '" #"',             external: '" ↗"'         },     }}

Use the variable in your markup:

<div class="content:hash content:external">…</div>

Use custom colors

Add a color

Add the primary color using #000, oklch(0% 0 none), or hsl(0 0% 0%).

export default {    variables: {        color: {            primary: '#000'         }    }}

Apply it using color-related syntax and even change the opacity.

<div class="fg:primary bg:primary/.5">…</div>
Generated CSS
@layer base, theme, preset, components, general;@layer general {    .bg\:primary\/\.5 {        background-color: rgb(0 0 0/0.5)    }    .fg\:primary {        color: rgb(0 0 0)    }}

If a color is used only once in all markups, you can optionally not abstract it into a token.

<button class="bg:#ceb195">Milk Tea</button>

Variables only support rgb and hsl, in the future, they will be compatible with all native CSS functions, such as rgba, hsla, lab, and others. #346

Add a color with opacity

Add color variables with opacity using #00000080, rgb(0 0 0/.5), or hsl(0 0% 0%/.5).

export default {    variables: {        primary: 'rgb(0 0 0/0.5)'     }}

Apply it using color-related syntax like fg:.

<div class="fg:primary">…</div>
Generated CSS
@layer base, theme, preset, components, general;@layer general {    .fg\:primary {        color: rgb(0 0 0/0.5)    }}

Color variables with opacity cannot use /alpha to change the opacity.

<div class="fg:primary/.5">…</div>

Add a color alias

Create an alias for a color to link its value to an existing color.

export default {    variables: {        secondary: '$color-white' /* secondary */     }}

Apply it using color-related syntax.

<div class="fg:secondary">…</div>
Generated CSS
@layer base, theme, preset, components, general;@layer general {    .fg\:secondary {        color: oklch(100% 0 none)    }}

For example, say you have multiple color variables referencing the same color token. If that color needs updating, you would only need to update the source instead of manually updating every instance of the color.

Add a color alias with opacity

Create an alias for a color with opacity to link its value to an existing color.

export default {    variables: {        color: {            primary: '$color-black/.5',     /*  <─┐ */             secondary: '$color-primary/.5'  /*  ──┘  linked to primary */         }    }}

Apply it using color-related syntax like fg:.

<div class="bg:primary fg:secondary">…</div>
Generated CSS
@layer base, theme, preset, components, general;@layer general {    .bg\:primary {        background-color: oklch(0% 0 none/0.5)    }    .fg\:secondary {        color: oklch(0% 0 none/0.25)    }}

As shown above, creating an alias secondary linked to an existing alias primary with opacity /.5 is possible, and the opacity will be multiplied 0.5 * 0.5 = 0.25.

Add color shades

Sets multiple shades for a single color.

export default {    variables: {        color: {            primary: {                 '': '#1192e8', /* primary */                 10: '#e5f6ff', /* primary-10 */                 20: '#bae6ff', /* primary-20 */             }         }    }}

Apply it using color-related syntax like fill:.

<svg class="fill:primary-20">20</svg>

Add colors based on modes

Add color variables in different theme modes.

export default {    variables: {        color: {            primary: '#ff0000'        }    },    modes: {        light: {            color: {                primary: '#000000'             }        },        dark: {            color: {                primary: '#ffffff'             }        }    }}

Using modes for variables, you can access a single source of truth and simplify the markup.

<div class="bg:primary">…</div>
Generated CSS
@layer base, theme, preset, components, general;@layer theme {    :root {        --color-primary: rgb(255 0 0)    }    @media (prefers-color-scheme:light) {        :root {            --color-primary: rgb(0 0 0)        }    }    @media (prefers-color-scheme:dark) {        :root {            --color-primary: rgb(255 255 255)        }    }}@layer general {    .bg\:primary {        background-color: var(--color-primary)    }}

Override default colors

Access the same key as the preset to override default colors, like blue-5 ~ blue-95.

export default {    variables: {        color: {            blue: '#4589ff'         }    }}

  • Master UI


© 2025 Aoyue Design LLC.MIT License
Trademark Policy