Gap
- Tailwind CSS version
- v1.2.0+
Utilities for controlling gutters between grid rows and columns.
Gap
Use .gap-{size}
to change the gutter size in grid layouts.
<div class="grid gap-1 grid-cols-2">
<!-- ... -->
</div>
<div class="grid gap-2 grid-cols-2">
<!-- ... -->
</div>
<div class="grid gap-6 grid-cols-2">
<!-- ... -->
</div>
Row Gap
Use .gap-y-{size}
to change the gutter size between rows in grid layouts.
<div class="grid gap-y-1 grid-cols-2">
<!-- ... -->
</div>
<div class="grid gap-y-2 grid-cols-2">
<!-- ... -->
</div>
<div class="grid gap-y-6 grid-cols-2">
<!-- ... -->
</div>
Note that prior to Tailwind v1.7.0, these utilities were named .row-gap-{size}
. For more information, see the upcoming changes guide.
Column Gap
Use .gap-x-{size}
to change the gutter size between columns in grid layouts.
<div class="grid gap-x-1 grid-cols-2">
<!-- ... -->
</div>
<div class="grid gap-x-2 grid-cols-2">
<!-- ... -->
</div>
<div class="grid gap-x-6 grid-cols-2">
<!-- ... -->
</div>
Note that prior to Tailwind v1.7.0, these utilities were named .col-gap-{size}
. For more information, see the upcoming changes guide.
Responsive
To control the gap at a specific breakpoint, add a {screen}:
prefix to any existing gap utility. For example, use md:gap-6
to apply the gap-6
utility at only medium screen sizes and above.
<div class="grid gap-4 sm:gap-6 md:gap-8 lg:gap-12 xl:gap-16 ...">
<!-- ... -->
</div>
For more information about Tailwind's responsive design features, check out the Responsive Design documentation.
Customizing
Gap values
By default Tailwind's gap scale matches your configured spacing scale.
You can customize the global spacing scale in the theme.spacing
or theme.extend.spacing
sections of your tailwind.config.js
file:
// tailwind.config.js
module.exports = {
theme: {
extend: {
spacing: {
+ '72': '18rem',
+ '84': '21rem',
+ '96': '24rem',
}
}
}
}
To customize the gap scale separately, use the gap
section of your Tailwind theme config.
// tailwind.config.js
module.exports = {
theme: {
extend: {
gap: {
+ '11': '2.75rem',
+ '13': '3.25rem',
}
}
}
}
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 gap utilities.
You can control which variants are generated for the gap utilities by modifying the gap
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: {
// ...
- gap: ['responsive'],
+ gap: ['responsive', 'hover', 'focus'],
}
}
Disabling
If you don't plan to use the gap utilities in your project, you can disable them entirely by setting the gap
property to false
in the corePlugins
section of your config file:
// tailwind.config.js
module.exports = {
corePlugins: {
// ...
+ gap: false,
}
}