Why is there white space on top?

Why is there white space on top?
0.0 0

#1
  1. why is there white space on top even though I set body as margin 0 which will make everything in it with margin 0?

  2. Off-topic question but when do we have to specify the width and height? I mean even if I don’t specify the distance, everything seems to be working all fine usually?


#2

It’s the h1's top margin leaking through the divs it’s in. Setting it to 0 should remove the white gap.

Block elements have 100% width by default. The height is as much as the element needs to contain its contents (which also applies to the body and html elements). Change them whenever you think an element should have different width and height.


#3

But I already set 0 for body which should already affect h1 though. Is there a reason why I need to specify for h1 again?


#4

Setting the body’s margin to 0 does just that. It doesn’t affect anything else inside the body. You need to set the margin on the h1 itself