Skip to content

Spacing children

This utility is used to space to consecutive children of a parent either vertically or horizontally. Many browser primitives and components include bottom (or other) margin by default.

In order to mitigate instances of undesired margin (especially in the case of nested components) the .space-* utility classes help with this. This article is helpful background reading: Margin considered harmful.

Example

Vertical

Item 1
Item 2
Item 3
Item 4
<div class="space-y space-y-6">
<div>…</div>
<div>…</div>
<div>…</div>
<div>…</div>
</div>

Horizontal

Item 1
Item 2
Item 3
Item 4
<div class="d-flex space-x space-x-2">
<span>…</span>
<span>…</span>
<span>…</span>
<span>…</span>
</div>

Container classes

To effect spacing of children relative to the parent, apply either .space-y (inline margin) or .space-x (block margin) to the parent container. Possible spacing values adhere to the utility spacing scale and are expressed in suffix values of 1-10.

X or Y

ClassDescriptionCopy
space-yZeros out bottom margin for all children
space-xZeros out left margin for all children

Additive Y classes

ClassREMPXTokenCopy
space-y-10.125rem2px—units-25
space-y-20.25rem4px—units-50
space-y-30.375rem6px—units-75
space-y-40.5rem8px—units-100
space-y-50.75rem12px—units-150
space-y-61rem16px—units-200
space-y-71.25rem20px—units-250
space-y-81.5rem24px—units-300
space-y-92rem32px—units-400
space-y-102.5rem40px—units-500

Additive X classes

ClassREMPXTokenCopy
space-x-10.125rem2px—units-25
space-x-20.25rem4px—units-50
space-x-30.375rem6px—units-75
space-x-40.5rem8px—units-100
space-x-50.75rem12px—units-150
space-x-61rem16px—units-200
space-x-71.25rem20px—units-250
space-x-81.5rem24px—units-300
space-x-92rem32px—units-400
space-x-102.5rem40px—units-500