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?
The body element has a default 8px margin indicated by the bar on top.
You can remove this margin by setting the top and left margin to zero.
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 .
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.
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
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