Internal spacing (Padding) creates space between the content of an element and its border. Unlike external spacing (margin), which determines the distance between elements, internal spacing determines how much space the content has within its frame. With CSS, we have full control over spacing and can set values for each side separately: top, right, bottom, and left.
| Value | Description |
|---|---|
| % (Percentage) | Specifies spacing in percentages relative to the width of the parent element (not the contained one!). For example: padding: 5%; |
| Length | Specifies spacing in various units:
|
| Auto | The browser automatically calculates the spacing. For padding, it is usually treated as 0, unless specifically supported in certain contexts. |
| Initial | Sets the value to the default value according to the CSS specification (for padding, this is 0). |
| Inherit | The element inherits the padding value from its parent element (by default padding is not an inherited property but can be forced with this value). |
| Unset | Resets the value – since padding is not an inherited property, it behaves the same as initial (value 0). |
The table below shows all main properties for controlling internal spacing. Use them to set the space between content and the element's border. Examples in the "Example" column are ready for direct copying into your CSS.
| Property | Example | Description |
|---|---|---|
| Basic Properties | ||
padding | padding: 10px; |
Shorthand property to set all four sides at once |
padding-top | padding-top: 20px; |
Sets the top internal spacing of an element |
padding-right | padding-right: 15px; |
Sets the right internal spacing of an element |
padding-bottom | padding-bottom: 10px; |
Sets the bottom internal spacing of an element |
padding-left | padding-left: 5px; |
Sets the left internal spacing of an element |
| Shorthand Syntaxes | ||
padding: 10px | padding: 10px; |
All four sides: 10px |
padding: 10px 20px | padding: 10px 20px; |
Top/Bottom: 10px, Left/Right: 20px |
padding: 10px 20px 30px | padding: 10px 20px 30px; |
Top: 10px, Left/Right: 20px, Bottom: 30px |
padding: 10px 20px 30px 40px | padding: 10px 20px 30px 40px; |
Top: 10px, Right: 20px, Bottom: 30px, Left: 40px |
| Other | ||
box-sizing: border-box | box-sizing: border-box; |
Includes padding and border in total width/height of element (recommended!) |