Photo by Lemuel Butler  on Unsplash


Natura11y provides six spacers used to generate the padding and margin utilites.


Padding and Margin Utilites

Apply the padding and margin utilites (.padding-{x} and .margin-{x}) to any selector. Here x equals the spacer amount (values 1-5). In Figure 1, each box has a different padding value applied.

Padding value 1 (all sides)


Padding value 2 (all sides)


Padding value 3 (all sides)


Padding value 4 (all sides)


Padding value 5 (all sides)


Padding value 6 (all sides)


<div class="padding-1">...</div>
<div class="padding-2">...</div>
<div class="padding-3">...</div>
<div class="padding-4">...</div>
<div class="padding-5">...</div>
Figure 1

In Figure 2, each box has a different margin value applied.

Margin value (all sides)


Margin value (all sides)


Margin value (all sides)


Margin value (all sides)


Margin value (all sides)


Margin value (all sides)


<div class="margin-1">...</div>
<div class="margin-2">...</div>
<div class="margin-3">...</div>
<div class="margin-4">...</div>
<div class="margin-5">...</div>
Figure 2

Direction Specific

Apply padding or margin to a specific side, top and bottom, or left and right. Figure 3 below provides these directional utilities using spacer value of 2.

<!-- Single side only (top, right, bottom, left) -->

<div class="padding-top-2">...</div>
<div class="padding-right-2">...</div>
<div class="padding-bottom-2">...</div>
<div class="padding-left-2">...</div>

<div class="margin-top-2">...</div>
<div class="margin-right-2">...</div>
<div class="margin-bottom-2">...</div>
<div class="margin-left-2">...</div>

<!-- Top and bottom only -->
<div class="padding-y-2">...</div>
<div class="margin-y-2">...</div>

<!-- Left and right only -->
<div class="padding-x-2">...</div>
<div class="margin-x-2">...</div>

<!-- Centering with margin -->
<div class="margin-x-auto">...</div>
Figure 3

Breakpoint Modifiers

Padding and margin utilities accept breakpoint modifiers.

With the HTML in Figure 4, the container starts with a padding value of 1. It then changes to a padding value of 5 at the large breakpoint.

<!-- With breakpoint modifiers -->

<div class="padding-1 padding-5--lg">...</div>
<div class="margin-1 margin-5--lg">...</div>
Figure 4

Related CSS Variables

Further customize Spacing by redefining any of their related CSS variables as shown below.

:root {
    --spacer-base: 1rem;
    --spacer-1: calc(var(--spacer-base) * 0.5);
    --spacer-2: calc(var(--spacer-base) * 1);
    --spacer-3: calc(var(--spacer-base) * 1.5);
    --spacer-4: calc(var(--spacer-base) * 2.5);
    --spacer-5: calc(var(--spacer-base) * 4);
    --spacer-6: calc(var(--spacer-base) * 6.5);