4

I'm using normalize.css, and I saw that it doesn't reset margins or padding for the <html> element. Since I assume they've done their research I was wondering: does the <html> element have a default margin or padding in any browser? Is it right of me to assume that it doesn't and that this is why normalize.css doesn't reset it?

  • @PortlandRunner Is it? Normalize.css only resets the margin for the body, and I'd assume they did their research.. –  Sep 30 '13 at 18:47
  • Questions like this are unimportant if you reset your CSS, which I highly recommend. Rajesh mentioned what tags automatically have padding, etc, but they differ for each browser. A good rule of thumb is to always reset your css. -- And by differ, I mean the padding, etc differs in each browser – Jacques ジャック Sep 30 '13 at 18:48
  • @Jack, I know resets are important, that's why I'm using normalize.css (which is very thoroughly researched and recommended by some of the best and brightest). It's just that I noticed that normalize.css doesn't reset margins or padding for the html element, which made me wonder why that is. Only explanation I can think of is that the html element doesn't have any margin or padding by default, but I don't know if that's true. Which is why I asked (I've updated my question to better reflect this). –  Sep 30 '13 at 18:52
  • @Samuel Oh, ok. Well in that case. The tag does not have any preset css rules. :D – Jacques ジャック Sep 30 '13 at 18:54

3 Answers3

4

The <html> tag does not have any CSS rules automatically applied to it. You can apply styles if you like, but the only time I've ever done it is to get 100% height and width.

Default styling for each browser:

http://mxr.mozilla.org/mozilla-central/source/layout/style/html.css

http://trac.webkit.org/browser/trunk/Source/WebCore/css/html.css

http://www.iecss.com/

Jacques ジャック
  • 3,682
  • 2
  • 20
  • 43
  • Ah, so that confirms my suspicions! Thank you for the sources, I wasn't able to find this myself. Many thanks! –  Sep 30 '13 at 19:01
1

With reference to http://www.w3.org/TR/CSS2/sample.html, no elements have default padding, but body, h1..h6, p, fieldset, form, ul, ol, dl, dir, menu, blockquote and dd have a margin by default

Rajesh
  • 3,743
  • 1
  • 24
  • 31
  • So no default margin or padding for the `` element. Do all browsers follow this spec? And is it the same for html5? –  Sep 30 '13 at 18:48
  • 4
    The `` element shouldn't have any display elements at all, IN THEORY, since display shouldn't start until ``. But Internet Explorer especially is an issue (for example, requiring `height: 100%` to get a full height document on the `` tag of all things). I would recommend just setting `html` with no padding and margins since that would be safest, going forward. I often combine it with body, like: `html, body {padding: 0; margin: 0}` – Mark Ormston Sep 30 '13 at 18:51
  • @MarkOrmston, That's what I did as well. But since normalize.css doesn't do that I was wondering if it was just something that everyone was doing out of habit, which isn't really necessary. –  Sep 30 '13 at 18:57
  • The sample style sheet for HTML 4 in the CSS 2.1 is partly quite outdated. Some parts of it never corresponded to browser reality, – Jukka K. Korpela Sep 30 '13 at 19:40
1

No specification prevents browsers from having a default nonzero padding or margin on the html element. Neither does any specification require or even suggest such defaults, and browsers are not known to have them. On the other hand, if some browser vendor decides otherwise, they probably have a good reason to do so, and we had better not interfere unless we know what we are doing.

So there is really no reason to reset padding and margin on the html element.

Jukka K. Korpela
  • 195,524
  • 37
  • 270
  • 390