w1coding.comAll tutorials

CSS Padding

CSS lessons
  1. Environment Setup
  2. Introduction
  3. Tdisplay
  4. Basics
  5. Editors
  6. Syntax
  7. Colors
  8. Background
  9. Borders
  10. Margins
  11. Padding
  12. Width And Height
  13. Outline
  14. Texts
  15. Fonts
  16. Icons
  17. Links
  18. Lists
  19. Display
  20. Tables
  21. Max And With
  22. Positon
  23. Z Index
  24. Dropdown
  25. Overflow
  26. Float
  27. Navigation
  28. Image Sprites

CSS Padding Properties

Basic Padding

The padding property creates space inside the border of an element, between the content and the border. It can be set using pixels, percentages, etc.

Example of Basic Padding: 20px on all sides

Individual Padding Sides

You can set padding individually on each side with padding-top, padding-right, padding-bottom, and padding-left.

Example of Top and Bottom Padding: 30px
Example of Left and Right Padding: 40px

Padding Shorthand

CSS allows you to set padding for all four sides in one line with shorthand. The values are applied in the order: top, right, bottom, left.

padding: 10px 20px 30px 40px;

This sets 10px for top, 20px for right, 30px for bottom, and 40px for left.

Example of Shorthand Padding

Percentage-based Padding

Padding can also be set in percentages, which are based on the width of the parent element. For example, padding: 5% would apply 5% padding relative to the parent’s width.

Example of Percentage-based Padding: 5%