CSS padding Property

Beginner
6 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The padding property is a shorthand that sets the inner spacing on all four sides of an element — between the content and the border. It sets padding-top, padding-right, padding-bottom, and padding-left.

Use one to four values (length or percentage). Negative values are invalid. It is not inherited. Initial value for each side is 0. The element’s background paints through the padding area.

Baseline · Widely available.

Not deprecated and not experimental. Core box-model spacing supported in all browsers for decades.

Padding vs margin.

padding is inside the border. margin is outside the border, between this element and its neighbors.

CSS Syntax

syntax.css
padding: [ <length> | <percentage> ]{1,4} | initial | inherit;

1 value = all sides. 2 values = top/bottom | left/right. 3 values = top | left/right | bottom. 4 values = top | right | bottom | left (clockwise).

Property Values

ValueDescriptionTry it
<length>Fixed size such as 16px or 1rem. Must be non-negativeTry it
Two valuesTop/bottom, then left/right — for example 10px 24pxTry it
Four valuesTop, right, bottom, left in clockwise orderTry it
<percentage>Relative to the containing block’s inline size (usually its width)Try it
Three valuesTop, left/right, then bottom — for example 8px 20px 16pxTry it
initialResets each side to 0Try it
inheritInherits the computed padding from the parentTry it

How to Use padding

Pick how many sides you need, then write one to four non-negative values.

  1. Decide the inner spacing: all sides equal, vertical/horizontal pairs, or each side.
  2. Write padding with 1–4 values (or use a longhand like padding-top).
  3. Remember that background color fills the padding area.
  4. With box-sizing: border-box, padding is included in the element’s width and height.
GoalTypical value
Equal space insidepadding: 1rem;
More side space than verticalpadding: 0.5rem 1.5rem;
Each side differentpadding: 8px 16px 12px 20px;

Live Preview

The amber area is padding. The white dashed box is the content. Change padding and watch the space inside the border grow.

Amber = padding (background shows through). White dashed = content box.

Box
Content

padding: 0

CSS Examples

Each snippet shows only the padding you are studying. Use Try It Yourself for a live editor.

Example 1 — One Value (All Sides)

Apply the same padding on every side.

CSS
<style>
  .box {
    padding: 1rem;
    border: 1px solid #ccc;
  }
</style>

<div class="box">Padded content</div>
Try It Yourself

How It Works

  1. One length. padding: 1rem sets top, right, bottom, and left to 1rem.
  2. Space is inside. The gap sits between the content and the border.
  3. Background fills it. The amber area in the preview is the padding zone.
  4. Same idea for any unit. px, em, and rem all work.

Example 2 — Two Values

Set vertical and horizontal padding with two values.

CSS
<style>
  .box {
    padding: 0.5rem 1.5rem;
    border: 1px solid #ccc;
  }
</style>

<div class="box">Card text</div>
Try It Yourself

How It Works

  1. First value. 0.5rem applies to top and bottom.
  2. Second value. 1.5rem applies to left and right.
  3. Read the pair. Think “vertical | horizontal.”
  4. Need three or four? Add a bottom-only third value, or go clockwise with four.

Example 3 — Four Values (Clockwise)

Set each side separately in top → right → bottom → left order.

CSS
<style>
  .box {
    padding: 8px 24px 16px 12px;
    border: 1px solid #ccc;
  }
</style>

<div class="box">Uneven padding</div>
Try It Yourself

How It Works

  1. Top. 8px is the first value.
  2. Right. 24px is the second value.
  3. Bottom. 16px is the third value.
  4. Left. 12px is the fourth value. Remember: clockwise from the top.

Edge Cases & Pitfalls

If the box looks bigger than expected, one of these is usually why.

negative

Negative padding is invalid

Unlike margin, padding cannot be negative. The declaration is ignored if you try.

percent

Percentages use the containing block width

Even top and bottom percentage padding resolve against the containing block’s inline size (usually width), not its height.

box-sizing

Default width does not include padding

With content-box, padding adds to the total size. Use box-sizing: border-box so width includes padding and border.

auto

auto is not valid for padding

Centering with auto is a margin trick. Padding has no auto keyword.

table

Some table parts ignore padding

Padding does not apply to table row groups, rows, or columns. It does apply to cells and most other elements.

Browser Support

padding is a browser CSS property for the box model. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

padding

Supported in all modern browsers and Internet Explorer for many years. Part of the CSS Box Model.

99% Box model support
Google Chrome 1+
Full support
Mozilla Firefox 1+
Full support
Apple Safari 1+
Full support
Microsoft Edge 12+
Full support
Opera 3.5+
Full support
Samsung Internet 1+
Full support
Internet Explorer 4+
Full support
padding Widely supported

Bottom line: Safe for every layout. Logical longhands like padding-block are newer; the classic padding shorthand is universal. It is not a runtime API.

Key Takeaways

  • Role: inner spacing between content and border on all four sides.
  • Shorthand: 1–4 non-negative values map to sides (clockwise when four).
  • Background: the element’s background paints through the padding area.
  • Not margin: padding is inside; margin is outside. No auto, no negatives.

One line: padding sets space inside the border — use 1–4 lengths or percentages, never negative.

Frequently Asked Questions

It is a shorthand that sets the inner spacing on all four sides of an element — between the content and the border — by setting padding-top, padding-right, padding-bottom, and padding-left.
Each side defaults to 0. Elements start with no padding unless you set it or a browser stylesheet adds some (rare for padding).
Padding is space inside the border, between the border and the content. Margin is space outside the border, between this element and its neighbors.
Yes. Percentage padding is calculated from the containing block’s inline size (usually its width), even for top and bottom padding.
No. Negative lengths are invalid for padding. Use margin if you need to pull elements closer.
It is Baseline and widely available in all browsers. It is a browser CSS property for the box model, not a Node.js feature.

Next: padding-block

Learn the logical shorthand for block-axis padding.

padding-block tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful