/    Sign up×
Reference /Pin to ProfileBookmark

The padding property is the shorthand property for padding-top, padding-right, padding-bottom, and padding-left (in that order).

Syntax

An element’s padding is the space between the content it contains and its border. In the shorthand format, padding can have between one to four values.

  • If it has one value, that value is applied to all four sides of the element.
  • If it has two values, the first value is applied to the top and bottom padding and the second value is applied to the left and right padding.
  • If it has three values, the first is applied to the top, second is applied to the left and right, and third is applied to the bottom.
  • If it has four values, the first value is applied to the top padding, second value to the right padding, third value to the bottom padding, and fourth value to the left padding.
/* single value - applied to all sides */
div.one {
  padding: 10px;
}

/* 2 values - 1st value applied to top & bottom, 2nd value applied to right & left */
div.one {
  padding: 10px 20px;
}

/* 3 values - 1st value applied to top, 2nd value applied to right & left, 3rd value applied to bottom */
div.one {
  padding: 10px 20px 30px;
}

/* 4 values - 1st value applied to top, 2nd value applied to right, 3rd value applied to bottom, 4th value applied to left */
div.one {
  padding: 10px 20px 30px 15px;
}

Values

length
Defines in length units (px, pt, em, etc.) the space (padding) between the content and the border of the element. Default value is 0.

%
Defines the space (padding) between the content and the border of the element in percentage of the width of the containing element.

initial
Sets the property to its default value.

inherit
Inherits this property’s value from its parent item.

Browser Compatibilty

Demos

Have a code example of padding? Submit a codepen.io demo and we'll showcase it here

to submit a demo.
CSS
×

Success!

Help @reference spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 1.18,
social: @webDeveloperHQ,
});

legal: ({
terms: of use,
privacy: policy
analytics: Fullres
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: Anonymous,
tipped: article
amount: 1000 SATS,

tipper: @dert,
tipped: article
amount: 1000 SATS,

tipper: @viney352,
tipped: article
amount: 10 SATS,
)...