Design Tokens

Scales

Create modular scale systems for typography and spacing using mathematical ratios based on musical intervals and the golden ratio.

Overview

The scale composables help you create harmonious, proportional design systems using modular scales. They generate scale variables based on mathematical ratios and powers, enabling consistent sizing relationships across typography, spacing, and other design elements.

Why use scale composables?

Scale composables help you:

  • Create harmonious proportions: Use time-tested ratios from music theory and mathematics for visually pleasing designs.
  • Maintain consistency: Apply the same scale ratio across all sizing decisions for a cohesive design system.
  • Scale systematically: Generate size variations using powers of your base scale for predictable growth.
  • Simplify sizing decisions: Replace arbitrary values with a systematic approach to sizing.

useScale

The useScale() function creates a set of predefined scale ratio variables based on musical intervals and the golden ratio. It also creates a default scale variable that references one of the predefined scales.

import { styleframe } from 'styleframe';
import { useScale } from '@styleframe/theme';

const s = styleframe();

const {
    scaleMinorSecond,      // 1.067
    scaleMajorSecond,      // 1.125
    scaleMinorThird,       // 1.2
    scaleMajorThird,       // 1.25
    scalePerfectFourth,    // 1.333
    scaleAugmentedFourth,  // 1.414
    scalePerfectFifth,     // 1.5
    scaleGolden,           // 1.618
    scale,                 // References minor-third by default
} = useScale(s);

export default s;

Each scale ratio is named after its musical interval or mathematical origin. These ratios have been used in design and architecture for centuries to create harmonious proportions.

The scale variable is a convenient reference to your chosen default scale. By default, it references --scale--minor-third, but you can customize this by passing a second argument to useScale().

Pro tip: The Perfect Fourth (1.333) and Major Third (1.25) are popular choices for web typography, offering a good balance between subtle and pronounced size differences. The Golden Ratio (1.618) creates more dramatic scaling, ideal for establishing clear visual hierarchy.

Customizing the Default Scale

You can specify which scale should be the default by passing a second argument:

import { styleframe } from 'styleframe';
import { useScale } from '@styleframe/theme';

const s = styleframe();

// Set Perfect Fourth as the default scale
const { scale } = useScale(s, 'perfect-fourth');

export default s;

Valid default scale values are: "minor-second", "major-second", "minor-third", "major-third", "perfect-fourth", "augmented-fourth", "perfect-fifth", and "golden".

Pro tip: Using the scale variable makes it easy to change your entire design system's scale in one place. You can also override it at different breakpoints or for specific components.

useScalePowers

The useScalePowers() function generates size multipliers by raising a scale to different powers, creating a systematic sizing system.

import { styleframe } from 'styleframe';
import { useScale } from '@styleframe/theme';

const s = styleframe();

const { scalePerfectFourth } = useScale(s);

// Create a sizing system from -3 to 6
const sizes = useScalePowers(s, scalePerfectFourth, [-3, -2, -1, 0, 1, 2, 3, 4, 5, 6]);

export default s;
Good to know: While useScalePowers() generates the multipliers, you'll typically want to use them with useMultiplier() to create properly named variables for your design system.

Positive powers multiply the scale (making things larger), while negative powers divide it (making things smaller). This creates a harmonious progression of sizes both above and below your base size.

Pro tip: Most design systems use a range from -2 to 5 or -3 to 6, providing enough variation for everything from small captions to large headings without excessive options.

useMultiplier

The useMultiplier() function creates a set of variables by multiplying a base variable by different multipliers. This is perfect for combining with useScalePowers() to create complete size scales.

import { styleframe } from 'styleframe';
import { useScale, useScalePowers, useMultiplier, useFontSize, defaultScalePowerValues } from '@styleframe/theme';

const s = styleframe();

const { scale } = useScale(s);
const { fontSize } = useFontSize(s, { default: '1rem' });

// Generate scale powers
const scalePowers = useScalePowers(s, scale);

// Create font size variables using the base fontSize and scale powers
const {
    fontSizeXs,  // Variable<'font-size--xs'>
    fontSizeSm,  // Variable<'font-size--sm'>
    fontSizeMd,  // Variable<'font-size--md'>
    fontSizeLg,  // Variable<'font-size--lg'>
    fontSizeXl,  // Variable<'font-size--xl'>
    fontSize2xl, // Variable<'font-size--2xl'>
} = useMultiplier(s, fontSize, {
    xs: scalePowers[-2],
    sm: scalePowers[-1],
    md: scalePowers[0],
    lg: scalePowers[1],
    xl: scalePowers[2],
    '2xl': scalePowers[3],
});

export default s;

The useMultiplier() function automatically:

  • Creates properly named variables following the base variable's naming pattern
  • Generates calc() expressions that reference the base variable
  • Provides type-safe return values with correct variable names
Pro tip: Using useMultiplier() with scale powers keeps your design system flexible. Change the base fontSize or scale variable, and all derived sizes update automatically throughout your design system.

Examples

Typography Scale

Here's how to create a complete typographic scale using a specific scale:

import { styleframe } from 'styleframe';
import { useScale, useScalePowers, useMultiplier, useFontSize } from '@styleframe/theme';

const s = styleframe();

// Set your preferred default scale
const { scale } = useScale(s);

// Define base font size
const { fontSize } = useFontSize(s, { default: '1rem' });

// Create typographic scale using the default scale variable
const scalePowers = useScalePowers(s, scale, [-2, -1, 0, 1, 2]);

// Create font size variables automatically
const {
    fontSizeXs,
    fontSizeSm,
    fontSizeMd,
    fontSizeLg,
    fontSizeXl,
} = useMultiplier(s, fontSize, {
    xs: scalePowers[-2],    // ~0.563rem
    sm: scalePowers[-1],    // ~0.750rem
    md: scalePowers[0],     // ~1.000rem
    lg: scalePowers[1],     // ~1.333rem
    xl: scalePowers[2],     // ~1.777rem
});

export default s;

Using the scale variable means you can change your entire design system's proportions by overriding just one variable.

Spacing Scale

Create a consistent spacing system using the same modular scale:

import { styleframe } from 'styleframe';
import { useScale, useScalePowers, useMultiplier, useSpacing } from '@styleframe/theme';

const s = styleframe();

// Use the Major Second scale (1.125) for subtle spacing differences
const { scale } = useScale(s);

// Define base spacing unit
const { spacing } = useSpacing(s, { default: '1rem' });

// Create spacing scale
const scalePowers = useScalePowers(s, scale, [-3, -2, -1, 1, 2, 3, 4, 5]);

// Create spacing variables automatically
const {
    spacing3xs,
    spacing2xs,
    spacingXs,
    spacingMd,
    spacingLg,
    spacingXl,
    spacing2xl,
    spacing3xl,
} = useMultiplier(s, spacing, {
    '3xs': scalePowers[-3],  // ~0.704rem
    '2xs': scalePowers[-2],  // ~0.790rem
    xs: scalePowers[-1],     // ~0.889rem
    md: scalePowers[1],      // ~1.125rem
    lg: scalePowers[2],      // ~1.266rem
    xl: scalePowers[3],      // ~1.424rem
    '2xl': scalePowers[4],   // ~1.602rem
    '3xl': scalePowers[5],   // ~1.802rem
});

export default s;

Scale Reference Guide

Here's a reference for each scale ratio and its typical use cases:

ScaleRatioUse Case
Minor Second1.067Very subtle scaling, ideal for fine-tuned adjustments
Major Second1.125Subtle but noticeable, great for spacing systems
Minor Third1.2Balanced scaling, versatile for most applications
Major Third1.25Popular for web typography, clear hierarchy
Perfect Fourth1.333Classic choice, strong but not overwhelming
Augmented Fourth1.414Square root of 2, mathematically derived
Perfect Fifth1.5Pronounced scaling, creates clear distinctions
Golden Ratio1.618Dramatic scaling, ideal for hero sections

Best Practices

  • Choose one primary scale for most of your design system to maintain consistency.
  • Use smaller ratios (1.125-1.25) for spacing and line-height where subtle differences work best.
  • Use larger ratios (1.333-1.618) for typography and major layout elements where clear hierarchy is important.
  • Limit your power range to avoid too many size options (typically -3 to 6 is sufficient).
  • Document your scale decisions so team members understand which scale to use for different purposes.
  • Test on real content to ensure your scale works well across different contexts and viewport sizes.
Interesting fact: Modular scales originated from music theory, where these same ratios define harmonious musical intervals. This mathematical harmony translates beautifully to visual design, creating naturally pleasing proportions.

FAQ