Padding
Utilities for controlling an element’s padding.
Class reference
Class | Properties |
---|---|
.p-0 | padding: 0; |
.p-1 | padding: 0.25rem; |
.p-2 | padding: 0.5rem; |
.p-3 | padding: 0.75rem; |
.p-4 | padding: 1rem; |
.p-5 | padding: 1.25rem; |
.p-6 | padding: 1.5rem; |
.p-8 | padding: 2rem; |
.p-10 | padding: 2.5rem; |
.p-12 | padding: 3rem; |
.p-16 | padding: 4rem; |
.p-20 | padding: 5rem; |
.p-24 | padding: 6rem; |
.p-32 | padding: 8rem; |
.p-40 | padding: 10rem; |
.p-48 | padding: 12rem; |
.p-56 | padding: 14rem; |
.p-64 | padding: 16rem; |
.p-px | padding: 1px; |
.py-0 | padding-top: 0; padding-bottom: 0; |
.px-0 | padding-left: 0; padding-right: 0; |
.py-1 | padding-top: 0.25rem; padding-bottom: 0.25rem; |
.px-1 | padding-left: 0.25rem; padding-right: 0.25rem; |
.py-2 | padding-top: 0.5rem; padding-bottom: 0.5rem; |
.px-2 | padding-left: 0.5rem; padding-right: 0.5rem; |
.py-3 | padding-top: 0.75rem; padding-bottom: 0.75rem; |
.px-3 | padding-left: 0.75rem; padding-right: 0.75rem; |
.py-4 | padding-top: 1rem; padding-bottom: 1rem; |
.px-4 | padding-left: 1rem; padding-right: 1rem; |
.py-5 | padding-top: 1.25rem; padding-bottom: 1.25rem; |
.px-5 | padding-left: 1.25rem; padding-right: 1.25rem; |
.py-6 | padding-top: 1.5rem; padding-bottom: 1.5rem; |
.px-6 | padding-left: 1.5rem; padding-right: 1.5rem; |
.py-8 | padding-top: 2rem; padding-bottom: 2rem; |
.px-8 | padding-left: 2rem; padding-right: 2rem; |
.py-10 | padding-top: 2.5rem; padding-bottom: 2.5rem; |
.px-10 | padding-left: 2.5rem; padding-right: 2.5rem; |
.py-12 | padding-top: 3rem; padding-bottom: 3rem; |
.px-12 | padding-left: 3rem; padding-right: 3rem; |
.py-16 | padding-top: 4rem; padding-bottom: 4rem; |
.px-16 | padding-left: 4rem; padding-right: 4rem; |
.py-20 | padding-top: 5rem; padding-bottom: 5rem; |
.px-20 | padding-left: 5rem; padding-right: 5rem; |
.py-24 | padding-top: 6rem; padding-bottom: 6rem; |
.px-24 | padding-left: 6rem; padding-right: 6rem; |
.py-32 | padding-top: 8rem; padding-bottom: 8rem; |
.px-32 | padding-left: 8rem; padding-right: 8rem; |
.py-40 | padding-top: 10rem; padding-bottom: 10rem; |
.px-40 | padding-left: 10rem; padding-right: 10rem; |
.py-48 | padding-top: 12rem; padding-bottom: 12rem; |
.px-48 | padding-left: 12rem; padding-right: 12rem; |
.py-56 | padding-top: 14rem; padding-bottom: 14rem; |
.px-56 | padding-left: 14rem; padding-right: 14rem; |
.py-64 | padding-top: 16rem; padding-bottom: 16rem; |
.px-64 | padding-left: 16rem; padding-right: 16rem; |
.py-px | padding-top: 1px; padding-bottom: 1px; |
.px-px | padding-left: 1px; padding-right: 1px; |
.pt-0 | padding-top: 0; |
.pr-0 | padding-right: 0; |
.pb-0 | padding-bottom: 0; |
.pl-0 | padding-left: 0; |
.pt-1 | padding-top: 0.25rem; |
.pr-1 | padding-right: 0.25rem; |
.pb-1 | padding-bottom: 0.25rem; |
.pl-1 | padding-left: 0.25rem; |
.pt-2 | padding-top: 0.5rem; |
.pr-2 | padding-right: 0.5rem; |
.pb-2 | padding-bottom: 0.5rem; |
.pl-2 | padding-left: 0.5rem; |
.pt-3 | padding-top: 0.75rem; |
.pr-3 | padding-right: 0.75rem; |
.pb-3 | padding-bottom: 0.75rem; |
.pl-3 | padding-left: 0.75rem; |
.pt-4 | padding-top: 1rem; |
.pr-4 | padding-right: 1rem; |
.pb-4 | padding-bottom: 1rem; |
.pl-4 | padding-left: 1rem; |
.pt-5 | padding-top: 1.25rem; |
.pr-5 | padding-right: 1.25rem; |
.pb-5 | padding-bottom: 1.25rem; |
.pl-5 | padding-left: 1.25rem; |
.pt-6 | padding-top: 1.5rem; |
.pr-6 | padding-right: 1.5rem; |
.pb-6 | padding-bottom: 1.5rem; |
.pl-6 | padding-left: 1.5rem; |
.pt-8 | padding-top: 2rem; |
.pr-8 | padding-right: 2rem; |
.pb-8 | padding-bottom: 2rem; |
.pl-8 | padding-left: 2rem; |
.pt-10 | padding-top: 2.5rem; |
.pr-10 | padding-right: 2.5rem; |
.pb-10 | padding-bottom: 2.5rem; |
.pl-10 | padding-left: 2.5rem; |
.pt-12 | padding-top: 3rem; |
.pr-12 | padding-right: 3rem; |
.pb-12 | padding-bottom: 3rem; |
.pl-12 | padding-left: 3rem; |
.pt-16 | padding-top: 4rem; |
.pr-16 | padding-right: 4rem; |
.pb-16 | padding-bottom: 4rem; |
.pl-16 | padding-left: 4rem; |
.pt-20 | padding-top: 5rem; |
.pr-20 | padding-right: 5rem; |
.pb-20 | padding-bottom: 5rem; |
.pl-20 | padding-left: 5rem; |
.pt-24 | padding-top: 6rem; |
.pr-24 | padding-right: 6rem; |
.pb-24 | padding-bottom: 6rem; |
.pl-24 | padding-left: 6rem; |
.pt-32 | padding-top: 8rem; |
.pr-32 | padding-right: 8rem; |
.pb-32 | padding-bottom: 8rem; |
.pl-32 | padding-left: 8rem; |
.pt-40 | padding-top: 10rem; |
.pr-40 | padding-right: 10rem; |
.pb-40 | padding-bottom: 10rem; |
.pl-40 | padding-left: 10rem; |
.pt-48 | padding-top: 12rem; |
.pr-48 | padding-right: 12rem; |
.pb-48 | padding-bottom: 12rem; |
.pl-48 | padding-left: 12rem; |
.pt-56 | padding-top: 14rem; |
.pr-56 | padding-right: 14rem; |
.pb-56 | padding-bottom: 14rem; |
.pl-56 | padding-left: 14rem; |
.pt-64 | padding-top: 16rem; |
.pr-64 | padding-right: 16rem; |
.pb-64 | padding-bottom: 16rem; |
.pl-64 | padding-left: 16rem; |
.pt-px | padding-top: 1px; |
.pr-px | padding-right: 1px; |
.pb-px | padding-bottom: 1px; |
.pl-px | padding-left: 1px; |
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.
<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.
<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>
Add padding to all sides
Control the padding on all sides of an element using the p-{size}
utilities.
<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.
all
sm
md
lg
xl
<div class="pt-8 sm:pr-6 md:pb-4 lg:pl-2 xl:p-0 ...">
<span class="bg-yellow-200">Target</span>
</div>
Target
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,
}
}