gap-* for uniform spacing in both directions, and reach for gap-x-* or gap-y-* when horizontal and vertical spacing should differ — a common need in wrapping tag lists and card grids.
Gap value scale
AtomicKit’s gap utilities follow a consistent spacing scale shared across the framework. Every value maps to arem unit with a pixel equivalent for reference:
| Class | Value | Pixels |
|---|---|---|
.gap-0 / .gap-x-0 / .gap-y-0 | 0 | 0px |
.gap-px / .gap-x-px / .gap-y-px | 1px | 1px |
.gap-1 / .gap-x-1 / .gap-y-1 | 0.25rem | 4px |
.gap-2 / .gap-x-2 / .gap-y-2 | 0.5rem | 8px |
.gap-3 / .gap-x-3 / .gap-y-3 | 0.75rem | 12px |
.gap-4 / .gap-x-4 / .gap-y-4 | 1rem | 16px |
.gap-6 / .gap-x-6 / .gap-y-6 | 1.5rem | 24px |
.gap-8 / .gap-x-8 / .gap-y-8 | 2rem | 32px |
.gap-12 / .gap-x-12 / .gap-y-12 | 3rem | 48px |
.gap-14 / .gap-x-14 / .gap-y-14 | 3.5rem | 56px |
The three gap families share the same value steps:
gap-* sets both axes at once, gap-x-* sets only the column (horizontal) gap, and gap-y-* sets only the row (vertical) gap. You can combine all three on the same element — gap-x-* and gap-y-* will override the corresponding axis set by gap-*.Uniform gap — button group
When spacing should be identical in all directions,gap-* is the simplest choice. A typical button group uses gap-3 or gap-4 to keep actions close together without crowding:
.flex-col:
Axis-specific gap — tag list
When a flex container wraps onto multiple lines, you often want more vertical breathing room between rows than horizontal space between items. Combinegap-x-* and gap-y-* to dial in each axis independently:
Gap vs margin
Both gap and margin can create visual space between elements, but they serve different purposes. Choosing the right one keeps your markup clean and your components portable.Use gap when…
- Spacing children inside a flex container you control
- All children in the row or column need the same spacing
- Children are reusable components that shouldn’t carry layout-specific styles
- You want spacing to disappear automatically at the container’s edges
Use margin when…
- Adding space between a component and unrelated siblings outside a flex parent
- Pushing one specific child away from others in a non-flex context
- Applying asymmetric offset to a single item (e.g.
margin-topon a section heading) - Working with elements in a block or inline flow rather than a flex container
Responsive variants
Gap utilities support the--on-* responsive suffix. Increase or decrease spacing at specific breakpoints to match the visual density appropriate for each screen size:
Responsive suffixes are mobile-first:
--on-s, --on-m, --on-l, --on-xl. A class without a suffix applies at all viewport sizes.Best practices
Start with gap-4 as your baseline
gap-4 (1rem / 16px) is a comfortable default for most UI components. Step up to gap-6 or gap-8 for section-level spacing and down to gap-2 or gap-3 for compact controls.Don't combine gap and child margins for the same axis
If you set
gap-x-6 on a container and also add margin-right to every child, the spacing will compound unpredictably. Pick one approach per axis and stay consistent.Use gap-0 to reset inherited spacing
If a parent’s gap is leaking into a nested flex container, add
gap-0 to the child container to reset it before applying the spacing you actually want.Match gap values to your spacing scale
AtomicKit’s gap scale is shared with padding and margin utilities. Using the same values across all spacing properties keeps your vertical rhythm consistent without extra thought.
Related pages
Flex Container
Set up block and inline flex containers
Direction & Wrap
Control which direction gap spacing is applied along