Nearby lessons
37 of 61📦 Tailwind CSS - Padding
📖 Padding Overview
Padding utilities in Tailwind CSS control the space between an element's content and its border. They are essential for creating proper spacing and visual hierarchy in your designs.
Tailwind provides a comprehensive set of padding utilities that work on all sides of an element or on specific sides individually.
🎯 All Sides Padding (p)
Use the p- prefix to apply padding to all sides of an element:
p-0- No paddingp-1- 4px paddingp-2- 8px paddingp-3- 12px paddingp-4- 16px paddingp-5- 20px paddingp-6- 24px paddingp-7- 28px paddingp-8- 32px paddingp-10- 40px paddingp-12- 48px paddingp-16- 64px paddingp-20- 80px paddingp-24- 96px paddingp-32- 128px paddingp-40- 160px paddingp-48- 192px paddingp-56- 224px paddingp-64- 256px paddingp-72- 288px paddingp-80- 320px paddingp-96- 384px padding
⬆️ Top Padding (pt)
Use pt- to apply padding only to the top of an element:
pt-0- No top paddingpt-1- 4px top paddingpt-2- 8px top paddingpt-4- 16px top paddingpt-8- 32px top paddingpt-16- 64px top padding
➡️ Right Padding (pr)
Use pr- to apply padding only to the right side of an element:
pr-0- No right paddingpr-2- 8px right paddingpr-4- 16px right paddingpr-8- 32px right paddingpr-16- 64px right padding
⬇️ Bottom Padding (pb)
Use pb- to apply padding only to the bottom of an element:
pb-0- No bottom paddingpb-2- 8px bottom paddingpb-4- 16px bottom paddingpb-8- 32px bottom paddingpb-16- 64px bottom padding
⬅️ Left Padding (pl)
Use pl- to apply padding only to the left side of an element:
pl-0- No left paddingpl-2- 8px left paddingpl-4- 16px left paddingpl-8- 32px left paddingpl-16- 64px left padding
↔️ Horizontal Padding (px)
Use px- to apply padding to both left and right sides (horizontal):
px-0- No horizontal paddingpx-2- 8px horizontal paddingpx-4- 16px horizontal paddingpx-6- 24px horizontal paddingpx-8- 32px horizontal paddingpx-12- 48px horizontal paddingpx-16- 64px horizontal padding
↕️ Vertical Padding (py)
Use py- to apply padding to both top and bottom sides (vertical):
py-0- No vertical paddingpy-2- 8px vertical paddingpy-4- 16px vertical paddingpy-6- 24px vertical paddingpy-8- 32px vertical paddingpy-12- 48px vertical paddingpy-16- 64px vertical padding
🔢 Arbitrary Values
Use square brackets to apply any custom padding value:
p-[10px]- Custom 10px paddingp-[2.5rem]- Custom 2.5rem paddingpx-[15%]- Custom 15% horizontal paddingpy-[1.2em]- Custom 1.2em vertical padding
📱 Responsive Padding
Combine padding utilities with responsive prefixes:
p-4 md:p-8- 16px padding, 32px on medium screenspx-2 lg:px-12- 8px horizontal, 48px on large screenspy-4 sm:py-6 xl:py-12- Responsive vertical padding
✅ Padding Best Practices
- Use consistent spacing: Stick to Tailwind's spacing scale for visual harmony
- Consider responsive design: Adjust padding for different screen sizes
- Combine with margin: Use padding for internal spacing, margin for external spacing
- Think about content: More padding for important content, less for dense information
- Test touch targets: Ensure buttons and links have adequate padding for mobile
- Use semantic spacing: Larger padding for sections, smaller for components
- Avoid over-padding: Too much padding can waste screen space