Padding

Understanding Padding

  • Padding creates space between the content of an element and its border.

  • It affects the element's box size, increasing the area that the background covers.

  • Padding can be set on all sides of an element: top, right, bottom, and left.

  • Supports individual side adjustments or simultaneous, symmetrical settings.

  • Does not affect the element's position relative to others but affects surrounding layout spacing.

Value Example
Unit
Description

Any number

px

Pixels - a fixed unit of measurement.

Any number

rem

Relative to the font-size of the root element.

Any number

%

Percentage - relative to the width of the containing element.

Any number

vw

Relative to 1% of the width of the viewport.

N/A

initial

Resets the padding to the browser’s default value.

N/A

inherit

Inherits the padding value from the parent element.

N/A

unset

Removes any set padding, reverting to inherited if possible, otherwise to the initial value.

Example

  1. lets demonstrate padding with a card example, we have designed a blog card. Initially without padding it is looking like:

without padding on parent container

Now, we have applied the following padding to the parent block container

settings for parent block container
with padding on parent container

Last updated