WPLift is supported by its audience. When you purchase through links on our site, we may earn an affiliate commission.

Padding vs. Margin: Know the Difference in WordPress

Last Updated on November 29th, 2023

Tags: ,

Though the two may do similar things, there’s an important difference between padding and margin in WordPress that you need to know if you’re planning to customize your site with CSS. 

Below, we’ll outline the key differences between the two, why they’re used, and when to deploy each one to produce your desired results. 

What’s the Difference Between Padding and Margin in WordPress?

Both padding and margin are used to add space to your WordPress pages, though where each one adds that space, and how it affects your site differs from one to the next. 

In a nutshell, the term “padding” refers to the space surrounding your content within a block, while “margin” refers to the space separating individual blocks. 

Used effectively, both can prove invaluable for creating customizable layouts and improving the responsive design of your site to deliver optimum user experiences

You can see the key differences in the table below, after which you can read on to learn more about how, when, and where to apply each one in the WordPress website

PADDINGMARGIN
Adds space inside a block.Adds space outside a block.
It doesn’t affect other blocks on your page.Affects other blocks on your page.
Best for changing the style and layout of individual blocks.Best for changing the style and layout of your whole page. 
It only works on blocks with bordersWorks on all blocks with and without borders
It doesn’t support automatic and negative values.It supports automatic and negative values.
Background color of the added space can be customized.It only creates transparent space that can’t be customized. 

What is Padding in WordPress, and How Do You Use It? 

Padding is a CSS (Cascading Style Sheets) property that affects the area surrounding your content within a WordPress block, adding space around your content to enhance your site’s aesthetic appeal and usability.

For example, if you use a Paragraph block, and find that the text is crammed too close to the edge of that block, you might want to space things out to enhance readability.

To do that, you’d use padding. 

Article Continues Below

Here, you have two options. 

A. Controlling Padding Within the WordPress Editor 

The default WordPress post and page editor includes padding and margin controls for individual blocks. 

Padding Within the WordPress Editor 

To find it, make sure you have the block selected, then scroll down and tap Dimensions.

select Padding

Next, select Padding

You can then control how much padding you have both at the top and bottom of your block…

Controlling Padding Within the WordPress Editor - dimesions

…As well as around the sides. 

Padding Options in the WordPress Editor 

By default, the WordPress editor adds equal space to each side. 

In other words, if you’re adding space to the inner sides of your block, adjusting the slider to 4 pixels will add a 4-pixel space to both the left and right of your content. 

Likewise, adjusting the top and bottom slider will add the same amount of space to your content’s top and bottom. 

In many cases, that works fine, but if you want to customize the space on each side (for example, adding more space to the left than the right), you can do that by accessing the padding options. 

Article Continues Below

accessing the padding options.

To do that, tap on the small icon that looks like a crosshairs. 

Padding Options in the WordPress Editor

From here, you can select either the top, bottom, left, or right-hand side of your content block and adjust the space next to each one individually.

Customizing Padding in the WordPress Editor 

Another thing the WordPress editor does by default is make it so that padding can only be adjusted by whole numbers between 1 and 6 pixels. 

Though you’ll rarely need more than 6 pixels of padding, there is likely to be a time when you want to adjust your padding by a certain fraction, such as 2.5 pixels or 3.75 pixels. 

Customizing Padding in the WordPress Editor 

You can do that by tapping the slider icon and manually entering the required padding size. 

B. Adding Padding Using CSS

The WordPress editor may be the easiest way to add and manage padding, but if you’re creating your own WordPress theme or making permanent, site-wide customizations, you may prefer to use CSS. 

Here, there are four values you can use to control each side of your content block: 

  • padding-top:
  • padding-right:
  • padding-bottom:
  • padding-left:

Here’s an example of how this might look:

Adding Padding Using CSS

Here, you can see that we’ve set the top and bottom padding to 25px and the right and left sides to 40px, giving our content plenty of breathing room.

Of course, adding all four values only makes your CSS file larger, which can negatively impact your site speed

Article Continues Below

One way to counter that is to simply use the padding: short-hand property, which allows you to add up to all four values in a single line of code. 

These values run in the following order: 

  1. Top
  2. Right
  3. Bottom
  4. Left
padding 25px 30px 35px 25px

So, in the image above, for example, you can see that the following values are set: 

  1. Top – 25 px
  2. Right – 30 px
  3. Bottom – 35 px
  4. Left – 25 px

However, if two or more of your sides have the same value, you can make this even shorter, like so: 

padding is 25px 30px 35px

In this case, the top padding is 25px, the bottom padding is 35px, and the left and right are set at 30px. 

If you set the right-hand padding to 30px but don’t specify a left-hand value, the CSS automatically uses the right-hand value, thus making them the same. 

This can be shortened even further if you have one value for left and right padding and another for top and bottom, which would look like this: 

padding is 25px 30px

In this example, the top and bottom padding is 25px, while the left and right padding is 30px.

Finally, if you simply wanted to add the same amount of space to all four sides, you could do this with a single value like so: 

padding of 25px

In this case, all sides of the div will have a padding of 25px.

To learn more about how to edit your site this way, read our tutorial on how to add custom css to WordPress

What is Margin in WordPress and How Do You Use It? 

While padding lets you control the space inside a WordPress block, margins let you control the space outside that block. 

This can be useful for creating clean, user-friendly layouts by customizing the space between individual blocks. 

For example, if you had an image block underneath a paragraph block, you could use the margin CSS property to add more space between them, making your page feel less cluttered and easier to follow. 

As with padding, you can customize the margins between your blocks using either the WordPress editor or custom CSS. 

Let’s look at both in turn: 

A. Customizing Margins in the WordPress Editor 

You can adjust your margins in the WordPress editor in the same way you alter padding properties. 

First, select the block you want to change the margin for, then in the Block menu, select Dimensions.

click Margin

This time, click Margin.

Padding in WordPress margin editing

By default, you can add equal space to your block’s horizontal and vertical sides. 

fine-tune the spacing on individual sides in Padding in WordPress

Alternatively, you can tap the crosshairs icon to fine-tune the spacing on individual sides. 

Padding in WordPress - Dimensions

In the screenshot above, we’ve selected custom, which allows us to tweak each side separately.

 adjust top and margin top

However, if there’s only one side you need to adjust, you can also select that individually, as we’ve done here with the space at the top of our block. 

B. Customizing Margins in WordPress Using CSS

If you prefer to manage your margins with CSS, you can do that using the following four values: 

  • margin-top:
  • margin-right:
  • margin-bottom:
  • margin-left:

Here’s an example of how that might look in your CSS file: 

shorthand property

Again, you can reduce the amount of code you need by using a shorthand property, which in this case is: 

 margin:

The values that follow this property run in the same clockwise direction as padding, i.e., top, right, bottom, left like so:

margin 10px 20px 15px 25px

In this example, the top margin is 10px, the right margin is 20px, the bottom margin is 15px, and the left margin is 25px.

If one set of corresponding values (left/right or top/bottom) are the same, you can reduce this further to three values as shown here:

margin as 10px 20px 15px

This shows the top margin as 10px and the bottom as 15px, with the 20px value dictating both vertical sides. 

In cases where both sets of corresponding values are the same, you can use two values, one for horizontal spacing, and the other for vertical, such as: 

horizontal spacing

In this case, the values are applied as follows:

  • Top and bottom margin: 10px
  • Right and left margin: 20px

And, of course, if all your values are the same, you only need one value, for example: 

margin15px

In this case, a single value is applied to all four sides (top, right, bottom, and left), and all margins will have a value of 15px.

Using Auto and Negative Margin Values in CSS

One of the significant differences between padding and margins in WordPress is that the latter supports both auto and negative values. 

The auto value is often used to horizontally center an element within its container and automatically distribute the available space equally on the left and right sides.

auto horizontal margins

Here, you’ll need to specify the width of your block container, then use auto; value to divide the remaining space equally among the horizontal margins. 

Finally, you can also use negative values to create overlapping elements, a technique that’s perfect for creating unique grids and layouts. 

10px - 20px margin

In this example, a positive 10px margin is applied to the top, left, and bottom sides and a negative -20px margin is applied to the right side, which will cause the element to overlap its container on the right side by 20px.

When to Use Padding vs. Margin in WordPress

When to Use Margins 

The best time to use margins is when you want to affect the layout of your page.

Moving individual blocks up, down, left, or right with the margin CSS property affects other surrounding blocks, which overall impacts the entire page. As such, deploying it when you’re working on the page design is advisable. 

You can also use elements when you want to alter the space between two existing elements or create unique, overlapping blocks using negative values. 

When to Use Padding

The best time to use padding is when you want to create space between your content and the border of its containing block. 

This can be especially useful when incorporating responsive design elements such as clickable buttons. 

Adding padding around the button label will naturally expand the button’s size, making it more visible and easier to click on mobile devices. 

One important thing to note is that padding only affects elements with borders. So, if you’re using borderless blocks, you’ll need to reapply borders or try to achieve the same result using margins. 

On the plus side, padding does have one advantage over margin in that you can change the background color of the space you create to enhance the aesthetic appeal of your page further.

Margins don’t support this capability and only create transparent space, meaning the background stays the same as the rest of your page. 

Padding vs. Margin in WordPress: Key Differences Summed Up 

So, there you have it. You’ve learned everything you need to know about the key differences between padding and margin in CSS, and how it affects your WordPress design. 

For example, you now know that: 

  • Padding adds space inside an element – Use this CSS property to alter the distance between your content and its border.
  • Margin adds space outside the element – Use this property to change the distance between two blocks or to move elements around the page.
  • Both can be managed within WordPress or using custom CSS – The WordPress editor features padding and element controls under the Dimensions Tab. However, you can also use the padding; or margin; property in your CSS files.
  • Both have unique capabilities that can enhance your design – Margin allows you to overlap elements to create unique layouts, while padding allows you to change the background color of the space surrounding your content. 

Finally, it’s worth pointing out that you’ll get the most use out of padding and margin with a theme that relies on WordPress blocks. Check out our top 15 WordPress block themes for full website editing, and choose the perfect one for you.

A team of WordPress experts that love to test out new WordPress related software, WordPress plugins and WordPress themes.