Bootstrap Spacing Cheat Sheet

Padding All Sides (p-*)

Class rem Approx px Direction Usage
p-000pxAll sidesNo padding
p-10.25rem4pxAll sidesSmall padding
p-20.5rem8pxAll sidesMedium padding
p-31rem16pxAll sidesDefault padding
p-41.5rem24pxAll sidesLarge padding
p-53rem48pxAll sidesExtra large padding

Horizontal Padding (px-*)

Class rem Approx px Direction Usage
px-000pxLeft → RightNo horizontal padding
px-10.25rem4pxLeft → RightSmall horizontal padding
px-20.5rem8pxLeft → RightMedium horizontal padding
px-31rem16pxLeft → RightDefault horizontal padding
px-41.5rem24pxLeft → RightLarge horizontal padding
px-53rem48pxLeft → RightExtra large horizontal padding

Vertical Padding (py-*)

Class rem Approx px Direction Usage
py-000pxTop → BottomNo vertical padding
py-10.25rem4pxTop → BottomSmall vertical padding
py-20.5rem8pxTop → BottomMedium vertical padding
py-31rem16pxTop → BottomDefault vertical padding
py-41.5rem24pxTop → BottomLarge vertical padding
py-53rem48pxTop → BottomExtra large vertical padding

Individual Sides Padding (pt, pb, ps, pe)

Class Side rem Approx px Direction Usage
pt-*Top0-3rem0-48pxTop → DownTop padding only
pb-*Bottom0-3rem0-48pxBottom → UpBottom padding only
ps-*Left / Start0-3rem0-48pxLeft → RightLeft/start padding only
pe-*Right / End0-3rem0-48pxRight → LeftRight/end padding only

FAQ / Interview Questions

1. What is the difference between px-* and py-*?
Answer: px-* adds horizontal padding (left & right), py-* adds vertical padding (top & bottom).
2. What does p-* do?
Answer: p-* adds padding to all four sides (top, right, bottom, left).
3. Explain pt-*, pb-*, ps-*, pe-* classes.
Answer: These target individual sides: pt = top, pb = bottom, ps = left/start, pe = right/end.
4. How does Bootstrap use rem for spacing?
Answer: rem ensures spacing scales with root font size, making padding/margin responsive across devices.
5. What is the largest default padding class?
Answer: p-5 (3rem ≈ 48px).
6. How to center a div horizontally?
Answer: Use m-auto to set left & right margins automatically.
7. How to apply different horizontal and vertical padding?
Answer: Use both px-* and py-* together, e.g., class="px-3 py-2".