Skip to content

Spacing & Visibility

Margin, padding, and visibility utilities. Included in @grundtone/design-tokens CSS — see Installation for setup.

All utilities support responsive prefixes: sm:, md:, lg:, xl:, 2xl:.


How it works

Spacing utilities follow the pattern .{property}{direction}-{size}:

  • Property: m (margin) or p (padding)
  • Direction: blank (all), x (inline), y (block), t (top), b (bottom), s (start), e (end)
  • Size: 024 from the spacing scale

Inline directions (x, s, e) use CSS logical properties for automatic RTL support.


Margin

All sides

.m-4 — 1rem margin on all sides

Directional margin

Use t/b for top/bottom, s/e for inline-start/end (RTL-aware):

.ms-8 — margin-inline-start: 2rem (left in LTR)
.me-8 — margin-inline-end: 2rem (right in LTR)
.mt-6 — margin-top: 1.5rem
AbbreviationCSS propertyDescription
.m-{n}marginAll sides
.mx-{n}margin-inlineLeft + right (RTL-aware)
.my-{n}margin-blockTop + bottom
.mt-{n}margin-topTop only
.mb-{n}margin-bottomBottom only
.ms-{n}margin-inline-startStart (left in LTR, right RTL)
.me-{n}margin-inline-endEnd (right in LTR, left in RTL)

Auto margins

Centering with mx-auto

Center a block element horizontally:

.mx-auto — centered with auto inline margins

Pushing with mt-auto

Push an element to the bottom of a flex container:

Header
Footer — .mt-auto pushes to bottom
ClassCSSCommon use
.mx-automargin-inline: autoCenter block elements
.ms-automargin-inline-start: autoPush to end in flex row
.me-automargin-inline-end: autoPush to start in flex row
.mt-automargin-top: autoPush to bottom in flex column
.mb-automargin-bottom: autoPush to top in flex column
.m-automargin: autoCenter in both axes (with width)

Padding

All sides

.p-8 — 2rem padding on all sides

Axis padding

Use px for horizontal (inline) and py for vertical (block):

.px-12 — padding-inline: 3rem
.py-6 — padding-block: 1.5rem
AbbreviationCSS propertyDescription
.p-{n}paddingAll sides
.px-{n}padding-inlineLeft + right (RTL-aware)
.py-{n}padding-blockTop + bottom
.pt-{n}padding-topTop only
.pb-{n}padding-bottomBottom only
.ps-{n}padding-inline-startStart (left in LTR, right RTL)
.pe-{n}padding-inline-endEnd (right in LTR, left in RTL)

Responsive spacing

Add a breakpoint prefix to change spacing at different viewports:

.p-2 md:p-6 lg:p-10 — padding grows with viewport
html
<!-- Tight on mobile, spacious on desktop -->
<section class="p-2 md:p-6 lg:p-10">...</section>

<!-- No margin on mobile, auto-center from md -->
<div class="mx-0 md:mx-auto" style="max-width: 600px">...</div>

<!-- Stack tight, then add vertical spacing on desktop -->
<div class="my-2 lg:my-8">...</div>

Composing spacing

Combine multiple spacing classes on one element:

.px-4 .py-2 — different horizontal and vertical padding
.ps-8 .pe-2 — more start padding, less end padding
.ms-auto .me-4 — pushed right with end margin
html
<!-- Different horizontal and vertical padding -->
<div class="px-4 py-2">...</div>

<!-- Asymmetric inline padding -->
<div class="ps-8 pe-2">...</div>

<!-- Push right with auto + fixed margin -->
<div class="ms-auto me-4">...</div>

Spacing scale

The scale matches the gap utilities for consistency. Values use rem (relative to root font size):

SuffixValuepxSuffixValuepx
00051.25rem20
px1px161.5rem24
0-50.125rem271.75rem28
10.25rem482rem32
1-50.375rem692.25rem36
20.5rem8102.5rem40
2-50.625rem10112.75rem44
30.75rem12123rem48
3-50.875rem14143.5rem56
41rem16164rem64
205rem80
246rem96

Visibility

Control element visibility without removing it from the layout.

invisible vs hidden

.invisible hides the element but keeps its space. .hidden removes it from the layout entirely:

A
C — gap preserved
A
C — B removed from layout
Visible
Visible
ClassCSSLayout space
.visiblevisibility: visibleKept
.invisiblevisibility: hiddenKept
.hiddendisplay: noneRemoved

When to use which: Use .invisible for skeleton loading states, fade transitions, or keeping layout stable. Use .hidden when the element should not affect layout at all.


Comparison with Bootstrap

FeatureBootstrap 5Grundtone
Naming.mt-md-3 (infix).md:mt-3 (prefix)
!importantOn every utilityNone
Scale0–5 (6 values)0–24 (25 values)
RTL support.ms-* / .me-*Same + px/mx use margin-inline
Logical propertiesOnly start/endAll inline directions
Visibility.visible / .invisibleSame, plus responsive variants
Responsive.mt-md-3.md:mt-3