Padding
Add padding to a single side
Control the padding on one side of an element using the utilities.
For example, pt-6
would add 1.5rem
of padding to the top of an element, pr-4
would add 1rem
of padding to the right of an element, pb-8
would add 2rem
of padding to the bottom of an element, and pl-2
would add 0.5rem
of padding to the left of an element.
Control the horizontal padding of an element using the px-{size}
utilities.
<div class="px-8"><span class="bg-yellow-200">Target</span></div>
Add vertical padding
Control the vertical padding of an element using the py-{size}
utilities.
<div class="py-8"><span class="bg-yellow-200">Target</span></div>
Control the padding on all sides of an element using the p-{size}
utilities.
Responsive
For more information about Tailwind’s responsive design features, check out the documentation.
all
sm
md
lg
xl
<div class="pt-8 sm:pr-6 md:pb-4 lg:pl-2 xl:p-0 ...">
</div>
Target
By default Tailwind provides 19 fixed padding utilities for each side and axis.
If you’d like to customize these values for 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 padding values, use the theme.padding
section of your tailwind.config.js
file.
Learn more about customizing the default theme in the theme customization documentation.
By default, only responsive variants are generated for padding utilities.
You can control which variants are generated for the padding utilities by modifying the padding
property in the section of your tailwind.config.js
file.
For example, this config will also generate hover and focus variants:
// tailwind.config.js
variants: {
// ...
- padding: ['responsive'],
+ padding: ['responsive', 'hover', 'focus'],
}
}
// tailwind.config.js
module.exports = {
corePlugins: {
// ...
+ padding: false,
}