CSS Padding
Padding means the space between the content of an element and it's border. There are many properties in CSS by which you can define the space between the border of an element and it's content. These properties can take a value in units or in percentage. We will discuss these properties here.Set Top Padding
The padding-top property allows us to set the top padding of an element.Example:
Output: This division has top padding of 20 pxThis paragraph has top padding of 1 cm
This division has top padding of 20 pxThis paragraph has top padding of 1 cm
Set Right Padding
The padding-right property will set the right padding of the element.Example:
Output: This division has right padding of 5 cmThis paragraph has right padding of 50 px
This division has right padding of 5 cmThis paragraph has right padding of 50 px
Set Bottom Padding
By using padding-bottom property, bottom padding can be set. Example:Output: This division has bottom padding of 10%
This division has bottom padding of 10%
Set Left Padding
You can set left padding of an element by using padding-left property.Example:
Output:This paragraph has left padding of 1 cm
This paragraph has left padding of 1 cm
Set All Padding in a Single Command
All the padding properties can be set by using a single command, padding.Example:
Output:This paragraph has 1.5 cm padding on all sides
This paragraph has 0.5 cm top, bottom padding; 2.5 cm right, left padding.
This paragraph has 10 px top padding; 2% right and left padding; 15 px bottom padding
This paragraph has 10 px top padding; 2% right padding; 15 px bottom padding; 20 px left padding
This paragraph has 1.5 cm padding on all sides
This paragraph has 0.5 cm top, bottom padding; 2.5 cm right, left padding.
This paragraph has 10 px top padding; 2% right and left padding; 15 px bottom padding
This paragraph has 10 px top padding; 2% right padding; 15 px bottom padding; 20 px left padding
