Padding utilities add space inside an element, between its content and its border. This helps make things look neat and easy to read.
Padding utilities in Tailwind
p-{size} // padding all sides
pt-{size} // padding top
pr-{size} // padding right
pb-{size} // padding bottom
pl-{size} // padding left
px-{size} // padding left and right
py-{size} // padding top and bottom{size} is a number or keyword like 0, 1, 2, 3, 4, 5, 6, 8, 10, etc., representing spacing steps.
Use px and py to add horizontal or vertical padding quickly.
p-4
pt-2
px-6
py-3
This page shows a white box with some text and a button. The paragraph uses py-2 and px-4 to add vertical and horizontal padding inside it. The button uses px-6 and py-2 to make the clickable area bigger and comfortable.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Padding Utilities Example</title> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="bg-gray-100 flex items-center justify-center min-h-screen"> <div class="bg-white border rounded shadow p-6 max-w-sm"> <h1 class="text-xl font-bold mb-4">Hello, Tailwind!</h1> <p class="py-2 px-4 bg-blue-100 rounded">This paragraph has vertical padding of 2 and horizontal padding of 4.</p> <button class="mt-4 bg-blue-500 text-white rounded px-6 py-2 hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-400"> Click me </button> </div> </body> </html>
Padding sizes in Tailwind are based on a scale, usually multiples of 0.25rem (4px). For example, p-4 equals 1rem (16px).
Use responsive prefixes like md:p-6 to change padding on different screen sizes.
Combine padding utilities with margin utilities to control spacing outside elements.
Padding utilities add space inside elements to improve layout and readability.
Use p-, pt-, pr-, pb-, pl-, px-, and py- to control padding on different sides.
They help create neat, comfortable designs without writing custom CSS.