Padding
Utilities for controlling an element's padding.
Add padding to a single side
Control the padding on one side of an element using the p{t|r|b|l}-{size}
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.
pt-8
pr-8
pb-8
pl-8
<div class="pt-8"><span class="bg-yellow-200">Target</span></div>
<div class="pr-8"><span class="bg-yellow-200">Target</span></div>
<div class="pb-8"><span class="bg-yellow-200">Target</span></div>
<div class="pl-8"><span class="bg-yellow-200">Target</span></div>
Add horizontal padding
Control the horizontal padding of an element using the px-{size}
utilities.
px-8
<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.
py-8
<div class="py-8"><span class="bg-yellow-200">Target</span></div>
Add padding to all sides
Control the padding on all sides of an element using the p-{size}
utilities.
p-8
<div class="p-8"><span class="bg-yellow-200">Target</span></div>
Responsive
To control the padding of an element at a specific breakpoint, add a {screen}:
prefix to any existing padding utility. For example, adding the class md:py-8
to an element would apply the py-8
utility at medium screen sizes and above.
For more information about Tailwind's responsive design features, check out the Responsive Design documentation.
<div class="pt-8 sm:pr-6 md:pb-4 lg:pl-2 xl:p-0 ...">
<span class="bg-yellow-200">Target</span>
</div>
Customizing
Padding scale
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.
// tailwind.config.js
module.exports = {
theme: {
padding: {
+ 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 padding utilities.
You can control which variants are generated for the padding utilities by modifying the padding
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: {
// ...
- padding: ['responsive'],
+ padding: ['responsive', 'hover', 'focus'],
}
}
Disabling
If you don't plan to use the padding utilities in your project, you can disable them entirely by setting the padding
property to false
in the corePlugins
section of your config file:
// tailwind.config.js
module.exports = {
corePlugins: {
// ...
+ padding: false,
}
}