CSS padding controls the space inside an element, creating spacing between the content and its border. Unlike margins (which create space outside an element), padding increases the internal space without affecting surrounding elements.
Property | Description |
---|---|
padding |
Shorthand for setting all four paddings (top, right, bottom, left). |
padding-top |
Sets the padding at the top of an element. |
padding-right |
Sets the padding at the right side. |
padding-bottom |
Sets the padding at the bottom. |
padding-left |
Sets the padding at the left side. |
The padding
property can be used to add equal space inside an element.
div {
padding: 20px; /* Adds 20px padding to all sides */
}
✅ Effect: The content inside the <div>
gets 20px space from its border on all sides.
You can specify different padding values for top, right, bottom, and left.
p {
padding: 10px 15px 20px 25px; /* top, right, bottom, left */
}
✅ Shorthand order:
padding: top right bottom left;
padding: top-bottom right-left;
Example: