Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Box Model and Sizing

The padding property

Reference for the CSS padding shorthand: one to four values, percentages, how padding interacts with box-sizing, syntax, examples and browser support.

The padding property sets the space inside an element, between its content and its border. Padding takes on the element's background, so it makes the box look bigger and gives text room to breathe. It is a shorthand for padding-top, padding-right, padding-bottom and padding-left.

Values are read clockwise from the top, and missing values are copied from the opposite side.

CSS
padding: 1rem;                 /* all four sides */
padding: 1rem 2rem;            /* top and bottom | left and right */
padding: 1rem 2rem 3rem;       /* top | left and right | bottom */
padding: 1rem 2rem 3rem 4rem;  /* top | right | bottom | left */

Try it

Padding shows the background
Padding and box-sizing

Syntax

CSS
padding: <padding-top>{1,4}

/* each value: */
<length> | <percentage>
  • Initial value: 0 for every side
  • Applies to: all elements except internal table row groups, header groups, footer groups, rows, and column groups; ::first-letter and ::first-line too
  • Inherited: no
  • Percentages: relative to the width of the containing block, for all four sides
  • Animatable: yes
  • Computed value: each side as a percentage or absolute length

Values

Value Description
<length> A fixed size such as 12px, 1rem or 2em.
<percentage> A share of the containing block's width, even for top and bottom.

Negative values and auto are not allowed.

Usage notes

  • Padding adds to the size when box-sizing is content-box (the browser default): a width: 200px box with padding: 30px is 260px wide. Setting box-sizing: border-box makes width include padding and border, which most stylesheets prefer.
  • No collapsing. Unlike margins, padding never merges with neighboring padding.
  • Percentages follow width. padding-top: 50% is half the container's width, which is a known trick for ratio boxes. Modern code should use aspect-ratio.
  • Clickable area. Padding on links and buttons is part of the click target, so generous padding helps touch users.
  • Background and overflow. The background paints under the padding (see background-clip), and scrollable content scrolls inside the padding box.
  • Inline elements. Horizontal padding pushes text apart; vertical padding paints the background but does not change the line height.
  • Logical alternatives. padding-inline and padding-block follow the writing mode.

Browser support

Supported in every browser.