CSS Padding

The CSS padding property is used to create space inside an element, between its content and its border. It helps in controlling the layout and improving the design of a webpage. Padding can be applied on all four sides of an element or individually on each side.

Key Points on CSS Padding:

Syntax for CSS Padding:

Syntax Example

/* Padding shorthand syntax */
        padding: top right bottom left;
        
        /* Example */
        padding: 20px 30px 10px 40px;

Examples of CSS Padding:

The following examples demonstrate the usage of different padding properties:

Code Example: Padding for All Sides

div {
            padding: 20px;
        }

Output

This div has padding of 20px on all sides.

Code Example: Individual Padding

div {
            padding-top: 10px;
            padding-right: 30px;
            padding-bottom: 20px;
            padding-left: 40px;
        }

Output

This div has different padding for each side.

Common Padding Properties:

Padding can greatly enhance the layout and design of a webpage. By adjusting padding, you can control the spacing around your content, making it more readable and visually appealing.