How come there is a vertical scrollbar visible with this HTML file?
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<style>
html, body {border:0; margin:0; padding:0; height:100%}
h1 {margin:1em}
</style>
</head>
<body>
<h1>Test</h1>
</body>
</html>
(or this jsFiddle)
The body has exactly the same height as the window, obviously. So, what makes the content larger? What am I missing?
(Tested with IE, FF, Chrome.)
This behaviour is called “collapsing margins“. Since your
h1element is the first child element ofbody, it tries to collapse margin with it and the margin ofh1ends up at thebodytag. Sincebodyis already 100% the added margin will make it larger than the viewport.Read more on collapsing margins on w3c