Space Between v1.3.0+

Utilities for controlling the space between child elements.

Class reference

Class Properties
.space-x-0 > * + * margin-left: 0;
.space-x-1 > * + * margin-left: 0.25rem;
.space-x-2 > * + * margin-left: 0.5rem;
.space-x-3 > * + * margin-left: 0.75rem;
.space-x-4 > * + * margin-left: 1rem;
.space-x-5 > * + * margin-left: 1.25rem;
.space-x-6 > * + * margin-left: 1.5rem;
.space-x-8 > * + * margin-left: 2rem;
.space-x-10 > * + * margin-left: 2.5rem;
.space-x-12 > * + * margin-left: 3rem;
.space-x-16 > * + * margin-left: 4rem;
.space-x-20 > * + * margin-left: 5rem;
.space-x-24 > * + * margin-left: 6rem;
.space-x-32 > * + * margin-left: 8rem;
.space-x-40 > * + * margin-left: 10rem;
.space-x-48 > * + * margin-left: 12rem;
.space-x-56 > * + * margin-left: 14rem;
.space-x-64 > * + * margin-left: 16rem;
.space-x-px > * + * margin-left: 1px;
.-space-x-1 > * + * margin-left: -0.25rem;
.-space-x-2 > * + * margin-left: -0.5rem;
.-space-x-3 > * + * margin-left: -0.75rem;
.-space-x-4 > * + * margin-left: -1rem;
.-space-x-5 > * + * margin-left: -1.25rem;
.-space-x-6 > * + * margin-left: -1.5rem;
.-space-x-8 > * + * margin-left: -2rem;
.-space-x-10 > * + * margin-left: -2.5rem;
.-space-x-12 > * + * margin-left: -3rem;
.-space-x-16 > * + * margin-left: -4rem;
.-space-x-20 > * + * margin-left: -5rem;
.-space-x-24 > * + * margin-left: -6rem;
.-space-x-32 > * + * margin-left: -8rem;
.-space-x-40 > * + * margin-left: -10rem;
.-space-x-48 > * + * margin-left: -12rem;
.-space-x-56 > * + * margin-left: -14rem;
.-space-x-64 > * + * margin-left: -16rem;
.-space-x-px > * + * margin-left: -1px;
.space-y-0 > * + * margin-top: 0;
.space-y-1 > * + * margin-top: 0.25rem;
.space-y-2 > * + * margin-top: 0.5rem;
.space-y-3 > * + * margin-top: 0.75rem;
.space-y-4 > * + * margin-top: 1rem;
.space-y-5 > * + * margin-top: 1.25rem;
.space-y-6 > * + * margin-top: 1.5rem;
.space-y-8 > * + * margin-top: 2rem;
.space-y-10 > * + * margin-top: 2.5rem;
.space-y-12 > * + * margin-top: 3rem;
.space-y-16 > * + * margin-top: 4rem;
.space-y-20 > * + * margin-top: 5rem;
.space-y-24 > * + * margin-top: 6rem;
.space-y-32 > * + * margin-top: 8rem;
.space-y-40 > * + * margin-top: 10rem;
.space-y-48 > * + * margin-top: 12rem;
.space-y-56 > * + * margin-top: 14rem;
.space-y-64 > * + * margin-top: 16rem;
.space-y-px > * + * margin-top: 1px;
.-space-y-1 > * + * margin-top: -0.25rem;
.-space-y-2 > * + * margin-top: -0.5rem;
.-space-y-3 > * + * margin-top: -0.75rem;
.-space-y-4 > * + * margin-top: -1rem;
.-space-y-5 > * + * margin-top: -1.25rem;
.-space-y-6 > * + * margin-top: -1.5rem;
.-space-y-8 > * + * margin-top: -2rem;
.-space-y-10 > * + * margin-top: -2.5rem;
.-space-y-12 > * + * margin-top: -3rem;
.-space-y-16 > * + * margin-top: -4rem;
.-space-y-20 > * + * margin-top: -5rem;
.-space-y-24 > * + * margin-top: -6rem;
.-space-y-32 > * + * margin-top: -8rem;
.-space-y-40 > * + * margin-top: -10rem;
.-space-y-48 > * + * margin-top: -12rem;
.-space-y-56 > * + * margin-top: -14rem;
.-space-y-64 > * + * margin-top: -16rem;
.-space-y-px > * + * margin-top: -1px;
.space-x-reverse > * + * --space-x-reverse: 1
.space-y-reverse > * + * --space-y-reverse: 1

Add horizontal space between children

Control the horizontal space between elements using the space-x-{amount} utilities.

1
2
3
<div class="flex space-x-4">
  <div>1</div>
  <div>2</div>
  <div>3</div>
</div>

Add vertical space between children

Control the horizontal space between elements using the space-y-{amount} utilities.

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

Reversing children order

If your elements are in reverse order (using say flex-row-reverse or flex-col-reverse), use the space-x-reverse or space-y-reverse utilities to ensure the space is added to the correct side of each element.

1
2
3
<div class="flex flex-row-reverse space-x-4 space-x-reverse">
  <div>1</div>
  <div>2</div>
  <div>3</div>
</div>

Responsive

To control the space between elements at a specific breakpoint, add a {screen}: prefix to any existing space utility. For example, adding the class md:space-x-8 to an element would apply the space-x-8 utility at medium screen sizes and above.

For more information about Tailwind's responsive design features, check out the Responsive Design documentation.

1
2
3
1
2
3
1
2
3
1
2
3
1
2
3

Customizing

Spacing scale

If you'd like to customize your values for space between, padding, margin, width, and height all at once, use the theme.spacing section of your tailwind.config.js file.

// tailwind.config.js
module.exports = {
theme: {
spacing: {
+     sm: '8px',
+     md: '16px',
+     lg: '24px',
+     xl: '48px',
}
}
}

To customize only the space between values, use the theme.space section of your tailwind.config.js file.

// tailwind.config.js
module.exports = {
theme: {
space: {
+     sm: '8px',
+     md: '16px',
+     lg: '24px',
+     xl: '48px',
}
}
}

Learn more about customizing the default theme in the theme customization documentation.

Responsive and pseudo-class variants

By default, only responsive variants are generated for space utilities.

You can control which variants are generated for the space utilities by modifying the space property in the variants section of your tailwind.config.js file.

For example, this config will also generate hover and focus variants:

// tailwind.config.js
module.exports = {
variants: {
    // ...
-   space: ['responsive'],
+   space: ['responsive', 'hover', 'focus'],
}
}

Disabling

If you don't plan to use the space utilities in your project, you can disable them entirely by setting the space property to false in the corePlugins section of your config file:

// tailwind.config.js
module.exports = {
corePlugins: {
    // ...
+   space: false,
}
}