Padding in CSS:

The padding property in CSS is use to clear area inside the border of a HTML element. You can also say that padding is use to create space between content and HTML element. We can not set color for padding because it is a transparent property.

We can set padding property for top, bottom, left and right. So we can set padding property in CSS in 5 different types.

  • padding: it will set padding from all four sides (shorthand property)
  • padding-top: it will only set padding from top
  • padding-right: it will only set padding from right
  • padding-bottom: it will only set padding from bottom
  • padding-left: it will only set padding from left

You can set the value of margin in pixels and in percentage also.

 Example:

In following example we are setting all four values

 Shorthand Property of Padding:

We can also use the shorthand property for Padding. Means we can set the same value in padding property and also we can set four different values in padding property.

When we set four different values in padding so the first value refers to “top”, second refer to “right”, third refer to “bottom” and last refers to “left”.

Example:

 Note:

You can also set the padding value in “negative” if it needs.

Leave a Reply

Your email address will not be published. Required fields are marked *