CSS Portal

CSS padding Property

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The padding property defines the inward space between an element’s content and its border — essentially the element’s internal breathing room inside the CSS box model. Because that space is inside the element’s box, increasing padding will change the amount of space available for the content and, depending on how the box is sized, can affect the element’s overall footprint on the page; this behavior is controlled by box-sizing. Padding is part of the element’s painted area and contributes to the visual relationship between content and its container.

Padding is painted with an element’s background and sits inside the border edge, which means a background fills the content area plus the padding area but stops at the border; the border itself visually separates the padded interior from surrounding elements, so padding and border work together to shape an element’s interior and edge appearance (background, border). Because the background extends into the padding, adjusting padding can noticeably change the look of backgrounds and backgrounds with transparency. Padding also increases the clickable or interactive area of elements (for example, links and buttons), which makes it a useful tool for improving usability and touch targets without altering visual spacing between elements.

Padding behaves differently from the space outside an element: margins. Unlike margins, padding never collapses with adjacent vertical spacing; it remains strictly inside the element’s box and will not combine with the margins of sibling or parent elements (margin). For inline-level elements, horizontal padding shifts surrounding text and affects line layout in predictable ways; vertical padding on inline elements contributes to the line box and can influence vertical alignment and line height, which may in turn change how lines wrap and stack.

Practical layout consequences arise because padding reduces the room available for content and can therefore trigger clipping, scrolling, or overflow behavior when content no longer fits; how that situation is handled depends on the element’s overflow handling (overflow). In responsive design and UI work, padding is commonly preferred for controlling internal spacing because it preserves the element’s margins and external relationships while increasing internal comfort for content and controls, improving readability and interaction without shifting external layout relationships.

Definition

Initial value
See individual properties
Applies to
All elements
Inherited
No
Computed value
See individual properties
Animatable
Yes
JavaScript syntax
object.style.padding

Interactive Demo

The rusty swing set creaked a lonely lullaby in the twilight, shadows lengthening like grasping fingers across the dew-kissed grass. A lone dandelion seed, adrift on the breeze, whispered secrets of faraway fields, of dandelion suns and galaxies spun from fluff. Somewhere, beyond the veil of dusk, a coyote laughed, echoing through the stillness like a forgotten memory.

Syntax

padding: [ <length> | <percentage> ]{1,4}

Values

  • <length>Specifies a non-negative fixed width.
  • <percentage>A percentage relative to the width of the containing block. Negative values are not allowed.

    Can have between 1 to 4 values:
    1 value, all 4 sides have the same padding.
    2 values, the top and bottom paddings are set to the first value and the right and left paddings are set to the second.
    3 values, the top is set to the first value, the left and right are set to the second, and the bottom is set to the third.
    4 values, they apply to the top, right, bottom, and left, respectively.

Example

    <div class="container">
<h2>CSS Padding Examples</h2>

<div class="box">Box with padding: 20px</div>

<div class="box-shorthand">Shorthand padding: 10px 20px</div>

<div class="box-individual">Individual paddings: top 8px / right 24px / bottom 32px / left 40px</div>
</div>
    body {
        font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
        padding: 24px;
        background: #fafafa;
    }

    .container {
        max-width: 720px;
        margin: 0 auto;
    }

    .box {
        padding: 20px;
        border: 2px solid #333;
        background: #f0f8ff;
        margin-bottom: 16px;
    }

    .box-shorthand {
        padding: 10px 20px; /* vertical | horizontal */
        border: 2px dashed #2b8a78;
        background: #fff8e1;
        margin-bottom: 16px;
    }

    .box-individual {
        padding-top: 8px;
        padding-right: 24px;
        padding-bottom: 32px;
        padding-left: 40px;
        border: 2px dotted #c34a4a;
        background: #f2fff2;
    }

Browser Support

The following information will show you the current browser support for the CSS padding property. Hover over a browser icon to see the version that first introduced support for this CSS property.

This property is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 1st January 2026

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!