Padding
Assign responsive-friendly padding
values to an element or a subset of its sides with shorthand classes. Includes support for individual properties, all properties, and vertical and horizontal properties. Classes are built from a default Sass map ranging from .25rem
to 9rem
.
Quick 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.5rem; |
.p-6 | padding: 3rem; |
.p-7 | padding: 6rem; |
.px-0 | padding-left: 0; padding-right: 0; |
.px-1 | padding-left: 0.25rem; padding-right: 0.25rem; |
.px-2 | padding-left: 0.5rem; padding-right: 0.5rem; |
.px-3 | padding-left: 0.75rem; padding-right: 0.75rem; |
.px-4 | padding-left: 1rem; padding-right: 1rem; |
.px-5 | padding-left: 1.5rem; padding-right: 1.5rem; |
.px-6 | padding-left: 3rem; padding-right: 3rem; |
.px-7 | padding-left: 6rem; padding-right: 6rem; |
.py-0 | padding-top: 0; padding-bottom: 0; |
.py-1 | padding-top: 0.25rem; padding-bottom: 0.25rem; |
.py-2 | padding-top: 0.5rem; padding-bottom: 0.5rem; |
.py-3 | padding-top: 0.75rem; padding-bottom: 0.75rem; |
.py-4 | padding-top: 1rem; padding-bottom: 1rem; |
.py-5 | padding-top: 1.5rem; padding-bottom: 1.5rem; |
.py-6 | padding-top: 3rem; padding-bottom: 3rem; |
.py-7 | padding-top: 6rem; padding-bottom: 6rem; |
.pt-0 | padding-top: 0; |
.pt-1 | padding-top: 0.25rem; |
.pt-2 | padding-top: 0.5rem; |
.pt-3 | padding-top: 0.75rem; |
.pt-4 | padding-top: 1rem; |
.pt-5 | padding-top: 1.5rem; |
.pt-6 | padding-top: 3rem; |
.pt-7 | padding-top: 6rem; |
.pb-0 | padding-bottom: 0; |
.pb-1 | padding-bottom: 0.25rem; |
.pb-2 | padding-bottom: 0.5rem; |
.pb-3 | padding-bottom: 0.75rem; |
.pb-4 | padding-bottom: 1rem; |
.pb-5 | padding-bottom: 1.5rem; |
.pb-6 | padding-bottom: 3rem; |
.pb-7 | padding-bottom: 6rem; |
.ps-0 | padding-left: 0; |
.ps-1 | padding-left: 0.25rem; |
.ps-2 | padding-left: 0.5rem; |
.ps-3 | padding-left: 0.75rem; |
.ps-4 | padding-left: 1rem; |
.ps-5 | padding-left: 1.5rem; |
.ps-6 | padding-left: 3rem; |
.ps-7 | padding-left: 6rem; |
.pe-0 | padding-right: 0; |
.pe-1 | padding-right: 0.25rem; |
.pe-2 | padding-right: 0.5rem; |
.pe-3 | padding-right: 0.75rem; |
.pe-4 | padding-right: 1rem; |
.pe-5 | padding-right: 1.5rem; |
.pe-6 | padding-right: 3rem; |
.pe-7 | padding-right: 6rem; |
Overview
The padding utilities that apply to all breakpoints, from xs
to xxl
, have no breakpoint abbreviation in them. This is because those classes are applied from min-width: 0
and up, and thus are not bound by a media query. The remaining breakpoints, however, do include a breakpoint abbreviation.
The classes are named using the format {property}{sides}-{size}
for xs
and {property}{sides}-{breakpoint}-{size}
for sm
, md
, lg
, xl
, and xxl
.
Where property is p
- for classes that set padding
:
Where sides is one of:
t
- for classes that setpadding-top
b
- for classes that setpadding-bottom
s
- (start) for classes that setpadding-left
in LTR,padding-right
in RTLe
- (end) for classes that setpadding-right
in LTR, orpadding-left
in RTLx
- for classes that set both*-left
and*-right
y
- for classes that set both*-top
and*-bottom
- blank - for classes that set a
padding
on all 4 sides of the element
Where size is one of:
0
- for classes that eliminate thepadding
by setting it to0
1
- (by default) for classes that set thepadding
to$spacer * .25
2
- (by default) for classes that set thepadding
to$spacer * .5
3
- (by default) for classes that set thepadding
to$spacer
4
- (by default) for classes that set thepadding
to$spacer * 1.5
5
- (by default) for classes that set thepadding
to$spacer * 3
6
- (by extended) for classes that set thepadding
to$spacer * 4
7
- (by extended) for classes that set thepadding
to$spacer * 5
8
- (by extended) for classes that set thepadding
to$spacer * 6
9
- (by extended) for classes that set thepadding
to$spacer * 7
10
- (by extended) for classes that set thepadding
to$spacer * 8
(You can add more sizes by adding entries to the $spacers
Sass map variable.)
Basic examples
Add padding to a single side
Use the p{t|s|b|e}-{size}
utilities to apply padding to an individual side, or the X and Y axis of an element.
For example, pt-4
would add 1.5rem
of padding to the top of an element, pe-3
would add 1rem
of padding to the right of an element, pb-5
would add 3rem
of padding to the bottom of an element, and ps-2
would add 0.5rem
of padding to the left of an element.
<div class="pt-4 ...">pt-4</div>
<div class="pe-3 ...">pe-3</div>
<div class="ps-2 ...">ps-2</div>
<div class="pb-5 ...">pb-5</div>
Add horizontal padding
Control the horizontal padding of an element using the px-{size}
utilities.
<div class="px-5 ...">px-5</div>
Add vertical padding
Control the vertical padding of an element using the py-{size}
utilities.
<div class="py-5 ...">py-5</div>
Add padding to all sides
Control the padding on all sides of an element using the p-{size}
utilities.
<div class="p-5 ...">p-5</div>
Breakpoints
All padding utilities that supports responsive at specific breakpoints, using the following format {property}{sides}-{breakpoint}-{size}
for xs
, sm
, md
, lg
, xl
, and xxl
.
For example, use py-md-5
to apply the py-5
utility at only medium screen
sizes and above.
<div class="py-sm-3 py-md-5 ...">py-sm-3 py-md-5</div>