Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is there a default margin on the <body> element? [closed]

Tags:

html

css

For most of my development career, I've only had to dabble in front-end, web based UI development. One thing has always bugged me is the constant need to reset browser-based styling "assumptions", which I've often forgotten until these defaults started effecting the layout of my pages.

The biggest assumption that most browsers make is that the HTML <body> element should have a margin, which almost always is 8px.

What was the design decision for this defaulted margin?

In fact, this margin is so undesirable that it is essentially standard practice to include this type of styling in a .css file which is included with every page of a site:

html, body {     margin: 0px; padding: 0px } 

IMHO, logic would dictate that most developers would want a full, blank slate that they can work with and format at their own discretion. With the browser defaulting a margin around the body element, the designer must remain conscientious of the spacing and add code to calculate correct layout for their inner elements if they don't reset the layout.

For what reason did the original developers of HTML browsers, or the initial HTML spec, decide to throw this default margin on all body elements?

like image 330
RLH Avatar asked Dec 31 '15 18:12

RLH


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.

How do I get rid of default body margins?

You can remove this margin by setting the top and left margin to zero.

What is the default margin in CSS?

By default, the left and right margins of a text element are set to 0 , but they all come with a margin-top and margin-bottom .

What is body margin?

Syntax: body { margin: size; } The margin property is a shorthand property having the following individual margin properties: margin-top: It is used to set the top margin of an element. margin-right: It is used to set the right margin of an element.


1 Answers

Languages are originally built to work independently. So that you could technically use that particular language for what is intended for only. In the case of HTML, it is only supposed to allow you to display something on a browser. CSS on the other hand (and as you surely know), is intended to create all the beautification process. So, with that in mind, Anyone should be able to write an HTML document without any CSS at all and browsers should display it in the most legible form. Now, for this to happen as consistent as possible, browsers have something called "sane defaults". These defaults cover the margin and padding on the body, some fonts, the most legible font size, etc. And they leave it up to you to overwrite as needed with CSS.

Without the margin and padding on the body, everything would be completely flushed to the browser window. That is not the best practice if you were reading a document.

EDIT

The links below show Firefox and Webkit CSS defaults. This will help you troubleshoot those defaults that you have no idea where they came from or why they exist.

Webkit

Firefox

like image 64
LOTUSMS Avatar answered Oct 03 '22 19:10

LOTUSMS