0% completed
CSS padding creates space inside an element between its content and border. It controls the inner spacing, making the content not stick directly to the edges. You can use padding as a shorthand property with one, two, or four values, or set each side's padding individually. This property is useful for improving the readability and layout of your elements.
Follow the code block below to set padding in CSS code.
/* Shorthand syntax for padding with 1, 2, or 4 values */ padding: 20px; /* 1 value: applies 20px of padding on all four sides */ padding: 10px 20px; /* 2 values: 10px for top and bottom; 20px for left and right */ padding: 5px 10px 15px 20px; /* 4 values: top, right, bottom, left respectively */ /* Individual padding properties */ padding-top: value; padding-right: value; padding-bottom: value; padding-left: value;
Explanation:
In this example, we apply one value for padding so that all four sides receive an equal amount.
Explanation:
50px
ensures 50px of space is applied uniformly to the top, right, bottom, and left.In this example, we use two values to set different padding for vertical and horizontal spacing.
Explanation:
10px
applies to the top and bottom, while the second value 20px
applies to the left and right.In this example, we set padding for each side individually using four values.
Explanation:
5px
, right padding is 10px
, bottom padding is 15px
, and left padding is 20px
.In this example, we apply individual padding properties for more control. We set separate values for the top and bottom, and use defaults for the left and right.
Explanation:
This lesson shows multiple ways to apply padding using both shorthand notation and individual properties. These techniques allow you to create well-spaced, organized layouts that enhance the visual appeal and readability of your elements.
.....
.....
.....