new course
CSS grid landing page tutorial (36min)

Lesson info

Lesson info

Padding and margin enable you to add space inside or outside of an element's boundary. Padding creates space on the inside, while margin creates space on the outside. These properties make it possible to create responsive websites with content that reflows — all while maintaining consistent spacing. 

In this article, we'll cover: 

  1. Adding margin to one side, opposite sides, or all sides at once
  2. Adding padding to one side, opposite sides, or all sides at once
  3. Negative margin
  4. Auto margin
  5. Centering elements horizontally

Explore this project

Want to dig into the project featured in this video and see how everything is put together? We've included the full project we used when making this lesson, and we've shared the link right under this very paragraph.

View and clone this projectDownload lesson assets
Clone this projectDownload project assets


Padding and margin can add space or breathing room inside or outside of an element's boundary. Padding creates space on the inside, while margin creates space on the outside.

Let's explore four different aspects of padding and margin: Individual Sides, Complementary Sides, All Sides, and then Negative Margin.

Let's start with Individual Sides. Here's a heading and an image — some paragraphs — not unlike many layouts. But if we select our heading and add some margin, we can eyeball this and click and drag to adjust. And once we get it just right, we can go down and apply that same class to another heading. And what we're getting at with this example is that we don't want to have to set margin (or any other style value) on individual elements. We're using classes to do the work for us. When we change the margin again on this one, it affects our original heading because it has the same class applied.

Let's select this image. And we can adjust the margin here to create more breathing room.

That's Individual Sides.

“Complementary Sides" simply refers to making padding and margin decisions on both sides (top and bottom; left and right...). If we grab this div block and style our class, we can hold option (or alt) and drag to add padding (breathing room on the inside). And it does this on both sides. Same thing on the top and bottom. We can hold option (or alt) and grab the top or bottom and drag to adjust both sides at once.

That's Complementary Sides.

All Sides is an extension of the same concept. If we want to adjust all four sides at once, hold down shift, and grab the padding (or margin) of one side, and the other three will follow suit.

Finally, let's touch on Negative Margin. Here's a simple section with an image. The image has a soft drop shadow, but that's not terribly important to this.

As we already know, we can add bottom margin on the image to push our paragraphs down. But we can also add negative top margin. And as we do this, as we click and drag to adjust, we can see the image overlap the previous section. Negative Margin does exactly what it's intended to and no, it's not a hack. In fact, Negative Margin is widely accepted as valid CSS.

So, we can adjust padding or margin on Individual Sides, Complementary Sides, or All Sides at once. We can even set Negative Margin to achieve many different effects, like overlapping content.

As a quick epilogue, we’ll make a note that although we clicked and dragged to adjust pixel values, we can also type in values for padding and margin at any time. We can just type in the unit, right after the number. And in some cases, we don’t even need to use numbers. Want to horizontally center an element using auto margin on both sides? Here’s the third most satisfying button to press in all of Webflow.

So, padding & margin: a great way to add or remove breathing room, inside or outside of an element’s boundary.