CSS Padding

CSS padding is a property that defines the space between an element's content and its border. It is used to add space around an element's content without affecting the element's width or height.

The padding property can take one to four values, each specifying the amount of padding to be applied to each side of the element. The values can be in pixels, ems, or percentages. If only one value is specified, it will be used for all sides. If two values are specified, the first will be used for the top and bottom, and the second will be used for the left and right. If three values are specified, the first will be used for the top, the second will be used for the left and right, and the third will be used for the bottom.

Here is an example of how to use the padding property:

div {
    padding: 20px;
  }

In this example, all sides of the div element will have 20 pixels of padding.

div {
    padding: 10px 20px;
  }

In this example, the top and bottom of the div element will have 10 pixels of padding, and the left and right will have 20 pixels of padding.

div {
    padding: 5px 10px 15px 20px;
  }

In this example, the top of the div element will have 5 pixels of padding, the right will have 10 pixels of padding, the bottom will have 15 pixels of padding, and the left will have 20 pixels of padding.

The padding property is commonly used to add space between an element's content and its border, which can help improve readability and make the content more visually appealing. It can also be used to create a background color or image for an element by setting the padding and then applying a background color or image to the element.

CSS Padding Properties

Property Description
padding Sets the padding for all four sides of an element
padding-top Sets the padding for the top side of an element
padding-right Sets the padding for the right side of an element
padding-bottom Sets the padding for the bottom side of an element
padding-left Sets the padding for the left side of an element

Each property can take a value in pixels, ems, or percentages, or can be set to inherit or initial. Multiple values can be specified for the padding property, in the order padding-top, padding-right, padding-bottom, padding-left