6️⃣

4.6 Box Model Padding

The CSS padding properties are used to generate space around an element's content, inside of any defined borders.
With CSS, you have full control over the padding. There are properties for setting the padding for each side of an element (top, right, bottom, and left).

Padding - Individual Sides

CSS has properties for specifying the padding for each side of an element:
  • padding-top
  • padding-right
  • padding-bottom
  • padding-left

Padding - Shorthand Property

To shorten the code, it is possible to specify all the padding properties in one property. The padding property is a shorthand property for specifying the padding for each side of an element.
If the padding property has four values:
  • padding: 25px 50px 75px 100px;
    • top padding is 25px
    • right padding is 50px
    • bottom padding is 75px
    • left padding is 100px
If the padding property has three values:
  • padding: 25px 50px 75px;
    • top padding is 25px
    • right and left paddings are 50px
    • bottom padding is 75px
If the padding property has two values:
  • padding: 25px 50px;
    • top and bottom paddings are 25px
    • right and left paddings are 50px
If the padding property has one value:
  • padding: 25px;
    • all four paddings are 25px
notion image
⚖️
Copyright © 2021 Code 4 Tomorrow. All rights reserved. The code in this course is licensed under the MIT License. If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact classes@code4tomorrow.org for inquiries.