CSS Padding
Welcome to the CSS Padding tutorial on codeswithpankaj.com
. In this tutorial, we will explore the padding
property in CSS, including individual padding properties (padding-top
, padding-right
, padding-bottom
, padding-left
) and shorthand notation.
CSS Padding Properties
1. Individual Padding Properties
CSS allows you to specify padding for each side of an element using individual properties:
padding-top
: Sets the padding for the top of the element.padding-right
: Sets the padding for the right side of the element.padding-bottom
: Sets the padding for the bottom of the element.padding-left
: Sets the padding for the left side of the element.
Example:
HTML:
2. Shorthand Padding Property
The padding
property allows you to specify all four paddings in a single declaration in the following order: padding: top right bottom left;
.
Example:
Here, 20px
is the top and bottom padding, and 30px
is the right and left padding.
HTML:
3. Practical Examples
Example 1: Using Individual Paddings
Example 2: Using Shorthand Padding
Conclusion
CSS padding properties (padding
, padding-top
, padding-right
, padding-bottom
, padding-left
) allow you to create space around elements on your web page effectively. By mastering these properties, you can control the spacing between content and the borders of elements. Stay tuned to codeswithpankaj.com
for more tutorials and web development tips!
Last updated