In W3 CSS and also in XUL/CSS? (not between CSS and XUL/CSS).
Padding is the space INSIDE an element (inside the border of the element).
Margin is the space OUTSIDE(Around) an element.
leftMargin
+ leftBorder
+ leftPadding
+ width
+ rightPadding
+ rightBorder
+ rightMargin
–
Cortisol I recommend this article for you. The diagram is from that article.
Padding is the space INSIDE an element (inside the border of the element).
Margin is the space OUTSIDE(Around) an element.
leftMargin
+ leftBorder
+ leftPadding
+ width
+ rightPadding
+ rightBorder
+ rightMargin
–
Cortisol Padding is the area between the content and the border while the margin is the area outside the border.
See CSS box model for clarification.
OK, several of these answers use confusing terminology and are wrong.
The css width of an element does not include padding, borders, or margin.
Therefore it is imprecise to say "padding is inside an element".
It is correct to say "padding is inside the border of an element" and "margin is outside the border of an element".
To calculate how much space a box takes up (for example, just horizontally):
horiz. space = width + 2(padding) + 2(border) + 2(margin)
It bugs me when people say "padding is space inside an element" because: the element has padding, it has a border, and it has margin. All of that stuff is outside the content width of the element, and must be accounted for when calculating how much space the element takes up.
If you say "padding is inside the element" then you are making the same mistake MSIE did in its broken box model, causing untold web designers many headaches.
http://www.456bereastreet.com/archive/200612/internet_explorer_and_the_css_box_model/
Margin is the space outside the border of an element. It creates space between the border of an element and its adjacent elements. It is used to control the external spacing between elements.
Padding is the space inside the border of an element. It creates space between the element's content and its border. It is used to control the internal spacing between the content and the border of an element.
padding is part of the width of an element. margin is outside and isn't part of the width
Here's an interesting box model demo that will help you understand.
#div1 {width: 500px; padding: 10px;}
will look bigger on the screen than #div2 {width: 500px; padding: 0px;}
(unless you're a broken MSIE box model: 456bereastreet.com/archive/200612/…) –
Nipper © 2022 - 2024 — McMap. All rights reserved.