1. css
  2. /properties
  3. /padding-left

padding-left

Definition

Setting a fixed padding value:

<div class="example-1">This is an example</div>
.example-1 {
  padding-left: 20px;
}

Setting a percentage padding value relative to the width of the containing block:

<div class="example-2">This is an example</div>
.example-2 {
  padding-left: 10%;
}

Using the padding shorthand property to set padding on all four sides of an element:

<div class="example-3">This is an example</div>
.example-3 {
  padding: 10px 20px 15px 5px;
}

Values

ValueDescription
lengthSpecifies a fixed padding in length units such as pixels (px) or ems (em).
percentageSpecifies a padding relative to the width of the containing block.
initialSets the property to its default value.
inheritInherits the property from its parent element.

Best Practices

  • Use padding to create space between an element's content and its border. This can improve the readability and visual appeal of your web page.
  • Avoid using fixed padding values for padding-left that are larger than the width of the containing block, as this can cause overflow issues.
  • Consider using percentage values for padding-left to create responsive designs that adapt to different screen sizes and device orientations.
  • Use the shorthand padding property to set padding on all four sides of an element. This can make your code more concise and easier to read.
  • Avoid using padding as a substitute for margins, which are better suited for creating space between elements. Use padding to create space within an element, and use margins to create space between elements.

Browser Compatibility

ChromeFirefoxSafariInternet ExplorerMicrosoft EdgeOpera
YesYesYesYesYesYes