Skip to main content

Overview

Use padding utilities to control the space inside elements. Padding creates space between an element’s content and its border. These utilities work with a consistent 4px scale and include both static and fluid variants for responsive designs.

Spacing Scale

All padding utilities follow a consistent 4px scale for predictable layouts.

Spacing Scale

00pxNo spacing
14pxFine adjustments
28pxSmall spacing
312pxMedium spacing
416pxStandard spacing
624pxLarge spacing
832pxExtra large spacing
1248pxSection spacing

All Sides Padding

Apply padding to all sides of an element at once.

All Sides Padding

.p-00padding: 0;No padding
.p-14pxpadding: 4px;Small padding
.p-28pxpadding: 8px;Small padding
.p-312pxpadding: 12px;Medium padding
.p-416pxpadding: 16px;Standard padding
.p-624pxpadding: 24px;Large padding
.p-832pxpadding: 32px;Extra large padding
.p-1248pxpadding: 48px;Section padding

Examples

<!-- All sides padding -->
<div class="p-4 bg-blue text-white">
  Standard padding all around
</div>

<!-- No padding -->
<div class="p-0 bg-gray-light">
  No internal spacing
</div>

Vertical Padding

Control top and bottom padding independently.

Top Padding

Top Padding

.pt-00padding-top: 0;No top padding
.pt-14pxpadding-top: 4px;Small top padding
.pt-28pxpadding-top: 8px;Small top padding
.pt-312pxpadding-top: 12px;Medium top padding
.pt-416pxpadding-top: 16px;Standard top padding
.pt-624pxpadding-top: 24px;Large top padding
.pt-832pxpadding-top: 32px;Extra large top padding

Bottom Padding

Bottom Padding

.pb-00padding-bottom: 0;No bottom padding
.pb-14pxpadding-bottom: 4px;Small bottom padding
.pb-28pxpadding-bottom: 8px;Small bottom padding
.pb-312pxpadding-bottom: 12px;Medium bottom padding
.pb-416pxpadding-bottom: 16px;Standard bottom padding
.pb-624pxpadding-bottom: 24px;Large bottom padding
.pb-832pxpadding-bottom: 32px;Extra large bottom padding

Examples

<!-- Top and bottom padding -->
<div class="pt-6 pb-4 px-4 bg-green text-white">
  Different top and bottom padding
</div>

<!-- Section with vertical padding -->
<section class="py-12">
  <h2 class="text-3xl font-bold mb-6">Section Title</h2>
  <p class="text-gray">Section content</p>
</section>

Horizontal Padding

Control left and right padding together.

Horizontal Padding

.px-2Horizontal8pxpadding-left: 8px; padding-right: 8px;Small horizontal padding
.px-3Horizontal12pxpadding-left: 12px; padding-right: 12px;Medium horizontal padding
.px-4Horizontal16pxpadding-left: 16px; padding-right: 16px;Standard horizontal padding
.px-6Horizontal24pxpadding-left: 24px; padding-right: 24px;Large horizontal padding
.px-8Horizontal32pxpadding-left: 32px; padding-right: 32px;Extra large horizontal padding

Vertical Padding

Control top and bottom padding together.

Vertical Padding

.py-2Vertical8pxpadding-top: 8px; padding-bottom: 8px;Small vertical padding
.py-3Vertical12pxpadding-top: 12px; padding-bottom: 12px;Medium vertical padding
.py-4Vertical16pxpadding-top: 16px; padding-bottom: 16px;Standard vertical padding
.py-6Vertical24pxpadding-top: 24px; padding-bottom: 24px;Large vertical padding
.py-8Vertical32pxpadding-top: 32px; padding-bottom: 32px;Extra large vertical padding

Examples

<!-- Horizontal and vertical padding -->
<div class="px-6 py-4 bg-green text-white">
  Horizontal and vertical padding
</div>

<!-- Mixed padding values -->
<div class="pt-6 pb-4 px-4 bg-red text-white">
  Mixed padding values
</div>

Fluid Padding

Fluid padding utilities use clamp() to scale smoothly between mobile and desktop sizes. They’re perfect for hero sections, marketing pages, and responsive layouts that need to adapt automatically.

All Sides Fluid Padding

Fluid Padding Utilities

ClassClamp ExpressionMobile → Desktop
.p-fluid-1clamp(0.25rem, calc(0.21rem + 0.09vw), 0.31rem)4px → 5px
.p-fluid-2clamp(0.5rem, calc(0.43rem + 0.18vw), 0.63rem)8px → 10px
.p-fluid-3clamp(0.75rem, calc(0.64rem + 0.27vw), 0.94rem)12px → 15px
.p-fluid-4clamp(1rem, calc(0.85rem + 0.37vw), 1.25rem)16px → 20px
.p-fluid-6clamp(1.5rem, calc(1.28rem + 0.56vw), 1.88rem)24px → 30px
.p-fluid-8clamp(2rem, calc(1.71rem + 0.74vw), 2.5rem)32px → 40px
.p-fluid-12clamp(3rem, calc(2.56rem + 1.1vw), 3.75rem)48px → 60px

Fluid Padding Top/Bottom

Fluid Padding Top

ClassClamp ExpressionMobile → Desktop
.pt-fluid-1clamp(0.25rem, calc(0.21rem + 0.09vw), 0.31rem)4px → 5px
.pt-fluid-2clamp(0.5rem, calc(0.43rem + 0.18vw), 0.63rem)8px → 10px
.pt-fluid-3clamp(0.75rem, calc(0.64rem + 0.27vw), 0.94rem)12px → 15px
.pt-fluid-4clamp(1rem, calc(0.85rem + 0.37vw), 1.25rem)16px → 20px
.pt-fluid-6clamp(1.5rem, calc(1.28rem + 0.56vw), 1.88rem)24px → 30px
.pt-fluid-8clamp(2rem, calc(1.71rem + 0.74vw), 2.5rem)32px → 40px

Fluid Padding Bottom

ClassClamp ExpressionMobile → Desktop
.pb-fluid-1clamp(0.25rem, calc(0.21rem + 0.09vw), 0.31rem)4px → 5px
.pb-fluid-2clamp(0.5rem, calc(0.43rem + 0.18vw), 0.63rem)8px → 10px
.pb-fluid-3clamp(0.75rem, calc(0.64rem + 0.27vw), 0.94rem)12px → 15px
.pb-fluid-4clamp(1rem, calc(0.85rem + 0.37vw), 1.25rem)16px → 20px
.pb-fluid-6clamp(1.5rem, calc(1.28rem + 0.56vw), 1.88rem)24px → 30px
.pb-fluid-8clamp(2rem, calc(1.71rem + 0.74vw), 2.5rem)32px → 40px

Fluid Padding Horizontal/Vertical

Fluid Padding Horizontal

ClassClamp ExpressionMobile → Desktop
.px-fluid-2clamp(0.5rem, calc(0.43rem + 0.18vw), 0.63rem)8px → 10px
.px-fluid-3clamp(0.75rem, calc(0.64rem + 0.27vw), 0.94rem)12px → 15px
.px-fluid-4clamp(1rem, calc(0.85rem + 0.37vw), 1.25rem)16px → 20px
.px-fluid-6clamp(1.5rem, calc(1.28rem + 0.56vw), 1.88rem)24px → 30px
.px-fluid-8clamp(2rem, calc(1.71rem + 0.74vw), 2.5rem)32px → 40px

Fluid Padding Vertical

ClassClamp ExpressionMobile → Desktop
.py-fluid-2clamp(0.5rem, calc(0.43rem + 0.18vw), 0.63rem)8px → 10px
.py-fluid-3clamp(0.75rem, calc(0.64rem + 0.27vw), 0.94rem)12px → 15px
.py-fluid-4clamp(1rem, calc(0.85rem + 0.37vw), 1.25rem)16px → 20px
.py-fluid-6clamp(1.5rem, calc(1.28rem + 0.56vw), 1.88rem)24px → 30px
.py-fluid-8clamp(2rem, calc(1.71rem + 0.74vw), 2.5rem)32px → 40px

Fluid Padding Examples

<!-- Hero section with fluid padding -->
<section class="py-fluid-12 px-fluid-6">
  <h1 class="text-fluid-6xl font-bold mb-fluid-4">Hero Title</h1>
  <p class="text-fluid-lg mb-fluid-8">Supporting text with fluid spacing</p>
</section>

<!-- Card with fluid padding -->
<div class="card p-fluid-6 mb-fluid-4">
  <h3 class="text-xl font-semibold mb-fluid-2">Card Title</h3>
  <p class="text-gray">Content with responsive padding</p>
</div>
Use fluid padding utilities for hero sections, marketing pages, and any content that needs to scale smoothly across viewport sizes. They work especially well when paired with fluid typography utilities.

Common Padding Patterns

Card with Consistent Padding

<div class="card p-6 mb-4">
  <h3 class="text-xl font-semibold mb-4">Card Title</h3>
  <p class="text-gray mb-4">Card description with consistent spacing.</p>
  <button class="btn btn-blue">Action</button>
</div>

Form Input Padding

<form class="max-w-md">
  <div class="mb-4">
    <label class="text-sm font-medium mb-2">Email</label>
    <input type="email" class="w-full p-3 border border-gray rounded">
  </div>
  <div class="mb-6">
    <label class="text-sm font-medium mb-2">Password</label>
    <input type="password" class="w-full p-3 border border-gray rounded">
  </div>
  <button class="btn btn-blue w-full">Submit</button>
</form>
<nav class="flex items-center justify-between px-6 py-4 bg-white">
  <h1 class="text-2xl font-bold">Logo</h1>
  <div class="flex gap-6">
    <a href="#" class="text-gray">Home</a>
    <a href="#" class="text-gray">About</a>
    <a href="#" class="text-gray">Contact</a>
  </div>
</nav>

Best Practices

1

Use the 4px Scale

Always use the predefined spacing scale (1, 2, 3, 4, 6, 8, 12) for consistency.
2

Consistent Internal Spacing

Use consistent padding values within components for better visual harmony.
3

Use Shorthand When Possible

Use .px-* and .py-* utilities when left/right or top/bottom values are the same.
4

Consider Content Density

Adjust padding based on content density and user experience needs.

Common Mistakes

Avoid these padding mistakes:
  • Don’t mix different spacing scales inconsistently
  • Don’t forget to consider mobile padding needs
  • Don’t use padding where margin would be more appropriate
  • Don’t over-pad small elements (keep proportions in mind)