What’s the default margin
that HTML sets for its <body>
tag? I noticed that there’s some automatic margin, but I’m wondering if anyone knows how much it is (and whether it’s in px
or %
, etc.).
The body element has a default 8px margin indicated by the bar on top.
By default, the margin value of some HTML elements is set to zero, though some elements have specified margin values as their default, such as the <h1> through <h6> heading tags. Margins of two different elements are also allowed to overlap sometimes in a behavior called margin collapse.
The default margins for Microsoft Word from version 2007 onward have been 1 inch (25.4 mm) all around; in Word 2003, the default top and bottom margins were 1 inch (25.4 mm), but 1.25 inches (31.7 mm) were given at the left and the right.
Margins are used to create space around elements, outside of any defined borders. This element has a margin of 70px.
In most major browsers, the default margin is 8px
on all sides. It is defined in pixels by the user-agent-stylesheet
your browser provides.
Some browsers allow you to create and use your own user-agent-stylesheet
, but if you are developing a website, I would recommend staying away from changing this, since your users most likely will not have a modified stylesheet and would then see a different page than you do.
If you want to change it, you can just do this:
body {
margin: 0px;
padding: 0px;
...
}
But if you have a large project and want to be more complete, use normalize.css. It resets a lot of default values to be consistent across browsers.
According to W3School's CSS reference, the default properties and values for a body tag are,
body{ display : block; margin : 8px; }
And one can quickly get the computed details of any element by accessing the Computed Pane in the Chrome Dev tools.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With