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 padding
  • p-1 - 4px padding
  • p-2 - 8px padding
  • p-3 - 12px padding
  • p-4 - 16px padding
  • p-5 - 20px padding
  • p-6 - 24px padding
  • p-7 - 28px padding
  • p-8 - 32px padding
  • p-10 - 40px padding
  • p-12 - 48px padding
  • p-16 - 64px padding
  • p-20 - 80px padding
  • p-24 - 96px padding
  • p-32 - 128px padding
  • p-40 - 160px padding
  • p-48 - 192px padding
  • p-56 - 224px padding
  • p-64 - 256px padding
  • p-72 - 288px padding
  • p-80 - 320px padding
  • p-96 - 384px padding
🌀

tailwind Designer

Live Component Playground

html Source
Loading...
Built with Tailwind CSS • Instant Reflection

⬆️ Top Padding (pt)

Use pt- to apply padding only to the top of an element:

  • pt-0 - No top padding
  • pt-1 - 4px top padding
  • pt-2 - 8px top padding
  • pt-4 - 16px top padding
  • pt-8 - 32px top padding
  • pt-16 - 64px top padding
🌀

tailwind Designer

Live Component Playground

html Source
Loading...
Built with Tailwind CSS • Instant Reflection

➡️ Right Padding (pr)

Use pr- to apply padding only to the right side of an element:

  • pr-0 - No right padding
  • pr-2 - 8px right padding
  • pr-4 - 16px right padding
  • pr-8 - 32px right padding
  • pr-16 - 64px right padding
🌀

tailwind Designer

Live Component Playground

html Source
Loading...
Built with Tailwind CSS • Instant Reflection

⬇️ Bottom Padding (pb)

Use pb- to apply padding only to the bottom of an element:

  • pb-0 - No bottom padding
  • pb-2 - 8px bottom padding
  • pb-4 - 16px bottom padding
  • pb-8 - 32px bottom padding
  • pb-16 - 64px bottom padding
🌀

tailwind Designer

Live Component Playground

html Source
Loading...
Built with Tailwind CSS • Instant Reflection

⬅️ Left Padding (pl)

Use pl- to apply padding only to the left side of an element:

  • pl-0 - No left padding
  • pl-2 - 8px left padding
  • pl-4 - 16px left padding
  • pl-8 - 32px left padding
  • pl-16 - 64px left padding
🌀

tailwind Designer

Live Component Playground

html Source
Loading...
Built with Tailwind CSS • Instant Reflection

↔️ Horizontal Padding (px)

Use px- to apply padding to both left and right sides (horizontal):

  • px-0 - No horizontal padding
  • px-2 - 8px horizontal padding
  • px-4 - 16px horizontal padding
  • px-6 - 24px horizontal padding
  • px-8 - 32px horizontal padding
  • px-12 - 48px horizontal padding
  • px-16 - 64px horizontal padding
🌀

tailwind Designer

Live Component Playground

html Source
Loading...
Built with Tailwind CSS • Instant Reflection

↕️ Vertical Padding (py)

Use py- to apply padding to both top and bottom sides (vertical):

  • py-0 - No vertical padding
  • py-2 - 8px vertical padding
  • py-4 - 16px vertical padding
  • py-6 - 24px vertical padding
  • py-8 - 32px vertical padding
  • py-12 - 48px vertical padding
  • py-16 - 64px vertical padding
🌀

tailwind Designer

Live Component Playground

html Source
Loading...
Built with Tailwind CSS • Instant Reflection

🔢 Arbitrary Values

Use square brackets to apply any custom padding value:

  • p-[10px] - Custom 10px padding
  • p-[2.5rem] - Custom 2.5rem padding
  • px-[15%] - Custom 15% horizontal padding
  • py-[1.2em] - Custom 1.2em vertical padding
🌀

tailwind Designer

Live Component Playground

html Source
Loading...
Built with Tailwind CSS • Instant Reflection

📱 Responsive Padding

Combine padding utilities with responsive prefixes:

  • p-4 md:p-8 - 16px padding, 32px on medium screens
  • px-2 lg:px-12 - 8px horizontal, 48px on large screens
  • py-4 sm:py-6 xl:py-12 - Responsive vertical padding
🌀

tailwind Designer

Live Component Playground

html Source
Loading...
Built with Tailwind CSS • Instant Reflection

✅ 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

🧠 Test Your Knowledge

4 Questions

Progress: 0 / 4
Keep Going!Tailwind CSS - Margin