Course contentsShow
← Web Development
Lesson 143 of 2,9823. CSS FundamentalsFree lesson

Padding Shorthand Syntax

Master the shorthand for setting padding on all four sides efficiently.

Padding Shorthand Syntax

What you'll learn: How to write padding values more efficiently using CSS shorthand notation.

The Long Way vs. The Short Way

You already know how to add padding to individual sides of an element using properties like padding-top, padding-right, padding-bottom, and padding-left. But CSS offers a much faster way to set multiple padding values at once using the padding shorthand property.

Think of it like giving directions: instead of saying "go north 10 steps, go east 5 steps, go south 10 steps, go west 5 steps," you could just say "10 north-south, 5 east-west." Shorthand syntax does exactly this for padding.

How Shorthand Works

The padding property accepts one to four values, and CSS interprets them differently based on how many you provide:

One value:

padding: 20px; /* All four sides get 20px */

Two values:

padding: 20px 40px; /* Top/Bottom: 20px, Left/Right: 40px */

Three values:

padding: 10px 20px 30px; /* Top: 10px, Left/Right: 20px, Bottom: 30px */

Four values:

padding: 10px 20px 30px 40px; /* Top, Right, Bottom, Left (clockwise) */

The four-value pattern follows a clockwise direction starting from the top—like reading a clock: 12, 3, 6, 9 o'clock positions.

When to Use What

Use shorthand when multiple sides share the same value or when you need to set all sides at once. It keeps your CSS cleaner and easier to maintain. For adjusting just one side, the individual properties (padding-top, etc.) remain perfectly valid.

Key Takeaway: The padding shorthand lets you set 1-4 padding values in a single line, following a clockwise pattern (top, right, bottom, left) that saves time and reduces code repetition.