The padding property is the shorthand property for padding-top, padding-right, padding-bottom, and padding-left (in that order).
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.
/* 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;
}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.
Have a code example of padding? Submit a codepen.io demo and we'll showcase it here ↴