Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How wide is the default `<body>` margin?

Tags:

html

css

margin

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.).

like image 952
John Avatar asked Oct 29 '12 18:10

John


People also ask

What is the default margin of the body element?

The body element has a default 8px margin indicated by the bar on top.

What is the default margin in HTML?

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.

What is margin width?

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.

Why does HTML body have margin?

Margins are used to create space around elements, outside of any defined borders. This element has a margin of 70px.


2 Answers

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.

like image 59
Jon Egeland Avatar answered Oct 12 '22 20:10

Jon Egeland


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.

like image 21
Vickar Avatar answered Oct 12 '22 18:10

Vickar