Spacing
Margin, padding, and gap utilities - generated from the spacing design token. All values are multiples of 0.5rem (8px) for a consistent, rhythmic layout system.
Spacing scale
ArchCSS uses a 7-step scale. The base unit is $spacer: 1rem (16px). Steps below and above multiply or divide that base.
| Token | Value | Pixels |
|---|---|---|
0 | 0 | 0px |
1 | 0.5rem | 8px |
2 | 1rem | 16px |
3 | 1.5rem | 24px |
4 | 2rem | 32px |
5 | 2.5rem | 40px |
6 | 3rem | 48px |
Margin
Apply margin to any side or axis with a shorthand class. Replace {n} with a token from the scale (0–6).
| Class | Property | Example |
|---|---|---|
.m-{n} | margin | .m-2 -> margin: 1rem |
.mt-{n} | margin-top | .mt-3 -> margin-top: 1.5rem |
.mr-{n} | margin-right | .mr-1 -> margin-right: 0.5rem |
.mb-{n} | margin-bottom | .mb-4 -> margin-bottom: 2rem |
.ml-{n} | margin-left | .ml-2 -> margin-left: 1rem |
.mx-{n} | margin-left + margin-right | .mx-3 -> margin: 0 1.5rem |
.my-{n} | margin-top + margin-bottom | .my-2 -> margin: 1rem 0 |
<!-- 1rem margin on all sides -->
<div class="m-2">...</div>
<!-- 1.5rem top margin, 0.5rem bottom margin -->
<p class="mt-3 mb-1">...</p>
<!-- 2rem left and right margin -->
<section class="mx-4">...</section>
Margin auto
Use auto margin utilities to horizontally or vertically center elements within their container.
Preview - centered box
<!-- Center a block element horizontally -->
<div class="mx-auto" style="width:200px">Centered</div>
<!-- Push all margin to the left (right-align) -->
<div class="ml-auto">Right-aligned</div>
<!-- Push all margin to the right (left-align inside flex) -->
<div class="mr-auto">Left-aligned</div>
| Class | Property |
|---|---|
.m-auto | margin: auto |
.mx-auto | margin-left: auto; margin-right: auto |
.my-auto | margin-top: auto; margin-bottom: auto |
.mt-auto | margin-top: auto |
.mr-auto | margin-right: auto |
.mb-auto | margin-bottom: auto |
.ml-auto | margin-left: auto |
Padding
Apply internal spacing with padding utilities. Same scale and directional shorthand as margin.
Preview - padding scale
0
8px
16px
24px
32px
40px
48px
<!-- 1.5rem padding on all sides -->
<div class="p-3">...</div>
<!-- 2rem horizontal, 1rem vertical -->
<button class="px-4 py-2">Click me</button>
<!-- 0.5rem top, 1.5rem bottom -->
<header class="pt-1 pb-3">...</header>
| Class | Property | Example |
|---|---|---|
.p-{n} | padding | .p-2 -> padding: 1rem |
.pt-{n} | padding-top | .pt-3 -> padding-top: 1.5rem |
.pr-{n} | padding-right | .pr-1 -> padding-right: 0.5rem |
.pb-{n} | padding-bottom | .pb-4 -> padding-bottom: 2rem |
.pl-{n} | padding-left | .pl-2 -> padding-left: 1rem |
.px-{n} | padding-left + padding-right | .px-3 -> padding: 0 1.5rem |
.py-{n} | padding-top + padding-bottom | .py-2 -> padding: 1rem 0 |
Gap
Control the spacing between flex or grid children using gap utilities. Same scale as margin and padding.
Preview - flex gap
.g-1 (0.5rem)
.g-3 (1.5rem)
.g-5 (2.5rem)
<!-- 1rem gap between flex children -->
<div class="flex g-2">
<div>Box A</div>
<div>Box B</div>
<div>Box C</div>
</div>
<!-- 2rem column gap, 1rem row gap in a grid -->
<div class="grid gx-4 gy-2">
<div>Item</div>
<div>Item</div>
</div>
| Class | Property | Example |
|---|---|---|
.g-{n} | gap | .g-2 -> gap: 1rem |
.gx-{n} | column-gap | .gx-3 -> column-gap: 1.5rem |
.gy-{n} | row-gap | .gy-2 -> row-gap: 1rem |
Named gap presets
Descriptive gap sizes that reference the configured grid gutter instead of the spacing scale.
<!-- Tight, gutter-size gap -->
<div class="flex normal-gap">
<div>Box A</div>
<div>Box B</div>
</div>
<!-- Preset scoped to one axis -->
<div class="grid large-gap-y">
<div>Item</div>
</div>
<!-- Remove the gap entirely -->
<div class="flex no-gap">
<div>Box A</div>
<div>Box B</div>
</div>
| Class | Value |
|---|---|
.narrow-gap | gap: 2px |
.small-gap | gap: gutter / 2 |
.normal-gap | gap: gutter |
.large-gap | gap: gutter / 1.5 |
.wide-gap | gap: gutter / 2 |
.no-gap | gap: 0 |
Each preset also ships -x and -y variants for one-axis gaps, e.g. .large-gap-y. Presets use the final $grid-gutter-width value, so they stay in sync when the gutter token changes.
Responsive spacing
All spacing utilities support responsive prefixes. Stack breakpoint variants to adjust spacing at different viewport widths - ArchCSS is mobile-first, so unprefixed classes apply at all sizes.
Example - responsive padding card
<!-- Small padding on mobile, larger on tablet and desktop -->
<section class="px-2 md:px-4 lg:px-6 py-3 lg:py-6">
<h1>Responsive section</h1>
</section>
<!-- Tight margin on mobile, auto-centered from md up -->
<div class="mx-2 md:mx-auto" style="max-width:720px">
<p>Centered content</p>
</div>
<!-- Responsive gap in a flex row -->
<div class="flex g-1 md:g-3 lg:g-5">
<div>Card</div>
<div>Card</div>
<div>Card</div>
</div>
| Prefix | Breakpoint | Example |
|---|---|---|
xs: | ≥ 375px | xs:p-2 |
sm: | ≥ 544px | sm:px-3 |
md: | ≥ 768px | md:px-4 |
lg: | ≥ 992px | lg:py-6 |
xl: | ≥ 1200px | xl:m-5 |
xxl: | ≥ 1440px | xxl:g-4 |
Mobile-first. A class likemd:px-4applies from themdbreakpoint (768px) and wider. Write the smallest spacing first, then layer larger values with breakpoint prefixes.