Skip to content

padding

Utilities for controlling an element's padding.

Quick reference

ClassStyles
p-<number>padding: calc(var(--spacing) * <number>);
p-pxpadding: 1px;
p-(<custom-property>)padding: var(<custom-property>);
p-[<value>]padding: <value>;
px-<number>padding-inline: calc(var(--spacing) * <number>);
px-pxpadding-inline: 1px;
px-(<custom-property>)padding-inline: var(<custom-property>);
px-[<value>]padding-inline: <value>;
py-<number>padding-block: calc(var(--spacing) * <number>);
py-pxpadding-block: 1px;
py-(<custom-property>)padding-block: var(<custom-property>);
py-[<value>]padding-block: <value>;
ps-<number>padding-inline-start: calc(var(--spacing) * <number>);
ps-pxpadding-inline-start: 1px;
ps-(<custom-property>)padding-inline-start: var(<custom-property>);
ps-[<value>]padding-inline-start: <value>;
pe-<number>padding-inline-end: calc(var(--spacing) * <number>);
pe-pxpadding-inline-end: 1px;
pe-(<custom-property>)padding-inline-end: var(<custom-property>);
pe-[<value>]padding-inline-end: <value>;
pt-<number>padding-top: calc(var(--spacing) * <number>);
pt-pxpadding-top: 1px;
pt-(<custom-property>)padding-top: var(<custom-property>);
pt-[<value>]padding-top: <value>;
pr-<number>padding-right: calc(var(--spacing) * <number>);
pr-pxpadding-right: 1px;
pr-(<custom-property>)padding-right: var(<custom-property>);
pr-[<value>]padding-right: <value>;
pb-<number>padding-bottom: calc(var(--spacing) * <number>);
pb-pxpadding-bottom: 1px;
pb-(<custom-property>)padding-bottom: var(<custom-property>);
pb-[<value>]padding-bottom: <value>;
pl-<number>padding-left: calc(var(--spacing) * <number>);
pl-pxpadding-left: 1px;
pl-(<custom-property>)padding-left: var(<custom-property>);
pl-[<value>]padding-left: <value>;

Source: https://tailwindcss.com/guide/padding

Examples

Basic example

Use p-<number> utilities like p-4 and p-8 to control the padding on all sides of an element:

html
<!-- [!code classes:p-8] -->
<div class="p-8 ...">p-8</div>

Adding padding to one side

Use pt-&lt;number&gt;, pr-&lt;number&gt;, pb-&lt;number&gt;, and pl-&lt;number&gt; utilities like pt-6 and pr-4 to control the padding on one side of an element:

html
<!-- [!code classes:pt-6,pr-4,pb-8,pl-2] -->
<div class="pt-6 ...">pt-6</div>
<div class="pr-4 ...">pr-4</div>
<div class="pb-8 ...">pb-8</div>
<div class="pl-2 ...">pl-2</div>

Adding horizontal padding

Use px-&lt;number&gt; utilities like px-4 and px-8 to control the horizontal padding of an element:

html
<!-- [!code classes:px-8] -->
<div class="px-8 ...">px-8</div>

Adding vertical padding

Use py-&lt;number&gt; utilities like py-4 and py-8 to control the vertical padding of an element:

html
<!-- [!code classes:py-8] -->
<div class="py-8 ...">py-8</div>

Using logical properties

Use ps-&lt;number&gt; or pe-&lt;number&gt; utilities like ps-4 and pe-8 to set the padding-inline-start and padding-inline-end logical properties, which map to either the left or right side based on the text direction:

html
<!-- [!code classes:ps-8,pe-8] -->
<!-- [!code word:dir="ltr"] -->
<!-- [!code word:dir="rtl"] -->
<div>
  <div dir="ltr">
    <div class="ps-8 ...">ps-8</div>
    <div class="pe-8 ...">pe-8</div>
  </div>
  <div dir="rtl">
    <div class="ps-8 ...">ps-8</div>
    <div class="pe-8 ...">pe-8</div>
  </div>
</div>

For more control, you can also use the LTR and RTL modifiers to conditionally apply specific styles depending on the current text direction.

Using a custom value

Use utilities like p-[&lt;value&gt;],px-[&lt;value&gt;], and pb-[&lt;value&gt;] to set the padding based on a completely custom value:

html
<div class="p-[5px] ...">
  <!-- ... -->
</div>

For CSS variables, you can also use the p-(&lt;custom-property&gt;) syntax:

html
<div class="p-(--my-padding) ...">
  <!-- ... -->
</div>

This is just a shorthand for p-[var(&lt;custom-property&gt;)] that adds the var() function for you automatically.

Responsive design

Prefix a padding utility with a breakpoint variant like md: to only apply the utility at medium screen sizes and above:

html
<div class="py-4 md:py-8 ...">
  <!-- ... -->
</div>

Learn more about using variants in the variants documentation.

Customizing your theme

The p-&lt;number&gt;,px-&lt;number&gt;,py-&lt;number&gt;,ps-&lt;number&gt;,pe-&lt;number&gt;,pt-&lt;number&gt;,pr-&lt;number&gt;,pb-&lt;number&gt;, and pl-&lt;number&gt; utilities are driven by the --spacing theme variable, which can be customized in your own theme:

css
@theme {
  --spacing: 1px;
}

Learn more about customizing the spacing scale in the theme variable documentation.

Released under the MIT License.