Home / Tips / Programming languages / Markup languages / HTML & CSS / What is the difference between margin and padding in CSS?

What is the difference between margin and padding in CSS?

CSS
 
CSS
  • Currently 5 out of 5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Rating: 5/5 (2 votes cast)

Thank you for rating!

You have already rated this page, you can only rate it once!

Your rating has been changed, thanks for rating!

Log in or create a user account to rate this page.


Padding sets space between a border and an element content. Margin sets space between a border and other outer elements.

When elements need space between them it's better to use margin. When text or inner elements need space between the parent element (box) and the text itself, then padding should be used.

Difference between margin and padding

Read more about it in the following article: how to set margins and paddings in CSS.


 

Read also

How to set margins and paddings in CSS

How to set margins and paddings in CSS

Details about "float" property

Details about "float" property

Discussion (total 1 comments)

sife
April 22, 2013 at 07:48 am
When elements need space between them it's better to use margin. When text or inner elements need space between the parent element (box) and the text itself, then padding should be used.
Some times I still get confuse between padding and margin, thank you for the advice.

Post comment

basicuse.net
html5_css
106160485398655174790

Quick navigation

General navigation