All Posts

How to use padding in Tailwind CSS

Padding is everywhere in web design. Every button, every card, every section needs proper spacing between its content and edges. Get it wrong and your interface looks cramped or weirdly stretched.

The old way meant writing custom CSS for every single element. You would end up with dozens of padding declarations scattered across your stylesheet, inconsistent values, and a maintenance headache.

Tailwind CSS changes this completely. With simple utility classes you can add padding to any element in seconds, keep your spacing consistent across the entire project, and make changes without touching a CSS file.

How padding classes work in Tailwind

Tailwind gives you a bunch of padding utilities that follow a simple pattern. The basic format is p- followed by a number, like p-4 or p-8.

These numbers map to Tailwind's spacing scale. By default, p-1 equals 0.25rem (4px), p-2 equals 0.5rem (8px), p-4 equals 1rem (16px), and so on. The scale goes all the way up to p-96 for really large spacing.

But you are not limited to padding all sides at once. Tailwind has utilities for every direction:

  • pt-4 adds padding to the top
  • pr-4 adds padding to the right
  • pb-4 adds padding to the bottom
  • pl-4 adds padding to the left

You can also use shortcuts for vertical and horizontal padding:

  • px-4 adds padding to left and right (horizontal)
  • py-4 adds padding to top and bottom (vertical)

Here is a visual example showing how these different utilities work:


Content with p-8 padding on all sides

Content with px-8 (left and right padding)

Content with py-8 (top and bottom padding)

Mixed padding: pt-8 pr-4 pb-2 pl-12

The colored backgrounds in this example make it easy to see exactly where the padding is applied. The white content box shows you the actual content area, while the colored area around it is the padding.

Picking the right padding utility for your needs

When you are working with padding in Tailwind, you have got choices. Do you pad all sides equally? Just horizontal or vertical? Or do you need fine control over each individual side?

Here is how I think about it.

Use p- for consistent spacing on all sides. This works great for buttons, badges, or any component where you want equal breathing room all around. A simple p-4 gives you uniform padding thats balanced and clean.

Use px- and py- when you need different spacing on different axes. Buttons are the perfect example – they usually need more horizontal padding than vertical. Something like px-6 py-3 creates that nice, wide button shape users expect.

Use individual side utilities when you need precise control. Sometimes you need extra padding on just one or two sides. Maybe you want more top padding to separate content from a header, or extra left padding to offset an icon. That is when pt-8 or pl-4 comes in handy.

Here is how this looks in practice with common UI elements:




Card Title

Card content goes here

Notice message

Extra left padding for the accent border

The key is matching the padding type to your design needs. Most of the time px- and py- will cover 80% of your use cases. Save individual side padding for those special situations where you need asymmetric spacing.

Using custom values and responsive padding

Sometimes Tailwind's default spacing scale does not have exactly what you need. Maybe your design calls for 14px of padding, but the scale only offers 12px (p-3) or 16px (p-4).

No problem. Tailwind lets you use arbitrary values with square brackets. Just write p-[14px] and you are set. You can use any CSS unit – pixels, rems, percentages, even calc() expressions.

Here are some examples:

  • p-[14px] – exactly 14 pixels
  • p-[2.5rem] – 2.5 rem units
  • p-[5%] – 5 percent of the parent
  • px-[calc(100%-2rem)] – calculated value

But here is my advice: stick to the default scale when you can. Arbitrary values are super useful but if you are using them constantly, you lose the consistency that makes Tailwind so powerful. Use them for those edge cases where you really need a specific value.

Now let's talk responsive padding. This is where Tailwind really shines.

You can add different padding at different screen sizes using breakpoint prefixes. Want less padding on mobile and more on desktop? Just combine utilities like this: p-4 md:p-8 lg:p-12.


Responsive Container

Padding increases on larger screens

Hero Section

More breathing room as the viewport expands

Mobile users get comfortable padding without wasting space. Desktop users get generous padding that takes advantage of the extra screen real estate. Everyone wins.

One thing to watch out for: don't go crazy with responsive padding. If you have padding changing at every single breakpoint, your HTML gets messy fast. Stick to 2-3 breakpoints max for most use cases.

Real-world padding patterns you can use

Alright, let's put everything together with some practical examples you can actually use in your projects. These are common UI patterns I see all the time, and the padding choices make a real difference in how professional they look.

Cards and panels: Cards need enough padding to let content breathe but not so much that they feel empty. I usually go with p-6 as a starting point. For larger cards or feature sections, bump it up to p-8 or even p-10.

Navigation bars: Horizontal navigation typically needs px-6 py-4 on the container and px-3 py-2 on individual nav links. This creates clickable areas that feel comfortable without making the navbar too tall.

Content sections: Page sections benefit from responsive padding. Start with py-12 px-4 on mobile and increase to py-20 px-8 on desktop. The generous vertical padding creates clear visual separation between sections.

Form elements: Input fields work best with compact padding like px-4 py-2. Too much padding makes them feel bloated. Buttons in forms usually want px-6 py-2.5 to stand out slightly more than inputs.

Here is a complete example showing all these patterns working together:

Real-World Example

  <!-- Card Grid -->
  <div class="grid md:grid-cols-2 gap-6">
    <div class="p-6 bg-white rounded-lg shadow-md">
      <h3 class="text-lg font-semibold mb-2">Feature Card</h3>
      <p class="text-gray-600">Consistent padding creates visual balance</p>
    </div>

    <div class="p-6 bg-white rounded-lg shadow-md">
      <h3 class="text-lg font-semibold mb-2">Another Card</h3>
      <p class="text-gray-600">Same padding maintains consistency</p>
    </div>
  </div>

  <!-- Form -->
  <form class="mt-8 p-6 bg-white rounded-lg shadow-md">
    <input type="email" placeholder="Your email" class="w-full px-4 py-2 border border-gray-300 rounded-lg">
    <button class="mt-4 px-6 py-2.5 bg-blue-500 text-white rounded-lg hover:bg-blue-600">
      Subscribe
    </button>
  </form>
</div>

These patterns work because the padding serves a purpose. Navigation needs enough padding for easy clicking. Cards need padding to separate content from edges. Forms need padding that makes inputs comfortable to use.

The best part? Once you establish these patterns in your project, you can reuse them consistently. Your p-6 cards always look the same. Your px-6 py-4 navigation feels familiar. Users get a cohesive experience and you get faster development.


That is everything you need to know about using padding in Tailwind CSS. Start with the default spacing scale, use axis utilities for most cases, add responsive padding where it makes sense, and save arbitrary values for special situations.

The patterns I showed you will cover 90% of what you build. Master these basics and you will create cleaner layouts with way less CSS.

Now go build something with better spacing!

Other posts you might like...

See more

Subscribe to our newsletter

Get notified when we add new templates, components, and more!

Thanks for subscribing!
Please check your email to confirm your subscription.

WindyBase Make development a breeze

WindyBase is a weekly curated Tailwind CSS template and tool directory built for the modern developer.

© 2025 WindyBase. All rights reserved.