CSS padding
CSS padding
is a shorthand property that defines the space between an element's border and its content, i.e., the padding on all four sides.
padding
When an element's padding is cleared, the released area will be filled with the element's background color.
Using the padding property alone can change the padding on all four sides.
Possible Values
Value | Description |
---|---|
length | Defines a fixed padding (pixels, pt, em, etc.) |
% | Uses percentage values to define padding |
Padding - Individual Side Padding Properties
In CSS, it can specify different padding for different sides:
Example
- Top padding is 25px
- Right padding is 50px
- Bottom padding is 25px
- Left padding is 50px
Padding - Shorthand Property
To shorten the code, it can specify all the padding properties in one attribute.
This is called a shorthand property. The shorthand property for all padding properties is padding
:
Example
padding: 25px 50px;
The padding property can have from one to four values.
padding: 25px 50px 75px 100px;
- Top padding is 25px
- Right padding is 50px
- Bottom padding is 75px
- Left padding is 100px
padding: 25px 50px 75px;
- Top padding is 25px
- Left and right padding is 50px
- Bottom padding is 75px
padding: 25px 50px;
- Top and bottom padding is 25px
- Left and right padding is 50px
padding: 25px;
- All four paddings are 25px
More Examples
All padding properties in one declaration
All CSS Padding Properties
Property | Description |
---|---|
padding | Sets all the padding properties in one declaration |
padding-bottom | Sets the bottom padding of an element |
padding-left | Sets the left padding of an element |
padding-right | Sets the right padding of an element |
padding-top | Sets the top padding of an element |