Foundations

Spacing

The spacing scale gives every margin, padding and gap a predictable size. It has 17 tokens built on an 8px base; 1px, 2px, 4px and 12px are for detail.

Every bar and diagram on this page is drawn with the var(--…) from the package, so it follows the package when it changes. See .claude/skills/eco-spacing for the rules.

Overview

Apply the scale to all margins, padding and position coordinates, on both the vertical and horizontal edges. Use it when you build a component or a page template. It must be used in all Alligo components and designs.

Most values are multiples of 8px. The 1px, 2px and 4px units are for detail level, and 12px is a complement when needed.

GroupTokensRangeTypical use

Scale

A systematic set for margins, padding, position coordinates and layout gaps. Each square is the real token size. Click a token to copy its variable.

ExampleDescriptionToken

Layout spacing

Two tokens change value with the breakpoint. Use them for the air between a section’s own content blocks, for example heading, card grid and buttons. Use the fixed scale above for margins and gutters.

Tokenxs 0–639sm 640–768md 769–1023lg 1024–1280xl 1281+
space-lg32px40px48px56px56px
space-md24px32px40px48px48px

These two are not in tokens.json. Link /components/css/spacing.css and use var(--dimension-spacing-space-md) or var(--dimension-spacing-space-lg): the value changes at each breakpoint by itself, so never write the pixel values by hand. They apply to every page, not only to parts built in Storyblok. No space-xs, space-sm or space-xl exists yet.

How to use

Spacing is applied by combining a token with a consumer class.

01 · Choose a spacing token

A token defines the size only. It maps directly to a pixel value in the spacing scale.

02 · Choose a consumer (where the space applies)

The consumer says which edge or axis gets the space.

GroupClassApplies to

Examples

One token and one consumer class per pattern.

Margin
<div class="space-24 mb-space">
  Element
</div>

Adds 24px space below the element.

Padding
<div class="space-12 px-space">
  Content
</div>

Adds 12px padding left and right.

Gap
<div class="space-24 gap-space">
  <div>A</div>
  <div>B</div>
</div>

Adds 24px spacing between child elements in both directions.

Reference

A strict directional reference. Each diagram maps one consumer class to one exact edge or axis. Blue marks the applied space; grey is the affected element or its children. Pick a token to redraw every diagram.

Token

Use one token for external margin, internal padding and the distance between children. X combines left + right and Y combines top + bottom.

Code

Always write the token with its pixel fallback. The list is generated from tokens.json.

All spacing tokens

    
Use in CSS
.card { padding: var(--dimension-spacing-space-16, 16px); }
.item { margin: var(--dimension-spacing-space-24, 24px) var(--dimension-spacing-space-8, 8px); }
.grid { display: grid; gap: var(--dimension-spacing-space-24, 24px); }
Page margin and gap per breakpoint (mobile first)
section { padding: 0 var(--dimension-spacing-space-16, 16px); }                 /* xs */
@media (min-width: 640px)  { section { padding: 0 var(--dimension-spacing-space-32, 32px); } }  /* sm, md */
@media (min-width: 1024px) { section { padding: 0 var(--dimension-spacing-space-40, 40px); } }  /* lg */

Usage

Do

  • Use a token for every margin, padding and gap.
  • Prefer 8px multiples; use 1, 2, 4 and 12px only for detail.
  • Use space-md / space-lg between a section’s own content blocks.
  • Write the token with its pixel fallback.

Don’t

  • Type a pixel value that has a token.
  • Stack two spacing values where one token would do.
  • Add a gap on top of an element’s own margin or padding.
  • Use a fixed token where the space should change per breakpoint.