CSS - Padding

CSS Padding

A padding is the space between an element's border and the content within it.The padding clears an area around the content (inside the border) of an element. The padding is affected by the background color of the element.

The top, right, bottom, and left padding can be changed independently using separate properties.

A shorthand padding property can also be used, to change all paddings at once. The padding CSS property sets the required padding space on all sides of an element.

The padding area is the space between the content of the element and its border. Negative values are not allowed.

The padding property in CSS defines the innermost portion of the box model, creating space around an element's content, inside of any defined margins and/or borders.Most of the rules for margins also apply to padding, except there is no "auto" value, and negative values cannot be declared for padding.

CSS Code

padding-top: length percentage; 
padding-left: length percentage;
padding-right: length percentage;
padding-bottom: length percentage;

In the above css code have 2 choices of values for the padding property −

  • length

  • percentage

You can also declare all the padding of an element in a single property as follows −

padding: 30px 30px 30px 30px;

If you declare all 4 values as I have above, the order is as follows −

top, right, bottom, left


p.padding {
font:"Times New Roman", Times, serif;
<p class="padding">Example of padding</p>