vadnica-logo
Editor My Blog My Services About the Project Telegram O meni O meni

CSS Padding

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.

EXAMPLE
RESULT
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:
  1. px (pixels): padding: 20px;
  2. em (relative to font size): padding: 2em;
  3. rem (relative to root element font size): padding: 2rem;
  4. vw (percentage of viewport width): padding: 5vw;
  5. vh (percentage of viewport height): padding: 5vh;
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).

Quick Reference: CSS Padding Properties

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
paddingpadding: 10px; Shorthand property to set all four sides at once
padding-toppadding-top: 20px; Sets the top internal spacing of an element
padding-rightpadding-right: 15px; Sets the right internal spacing of an element
padding-bottompadding-bottom: 10px; Sets the bottom internal spacing of an element
padding-leftpadding-left: 5px; Sets the left internal spacing of an element
Shorthand Syntaxes
padding: 10pxpadding: 10px; All four sides: 10px
padding: 10px 20pxpadding: 10px 20px; Top/Bottom: 10px, Left/Right: 20px
padding: 10px 20px 30pxpadding: 10px 20px 30px; Top: 10px, Left/Right: 20px, Bottom: 30px
padding: 10px 20px 30px 40pxpadding: 10px 20px 30px 40px; Top: 10px, Right: 20px, Bottom: 30px, Left: 40px
Other
box-sizing: border-boxbox-sizing: border-box; Includes padding and border in total width/height of element (recommended!)