1

When I set background-color, there are no white spaces as expected. My browser is chrome and it was a brand-new code, no other styles where applied in the CSS. Same thing happens with or without more components present in the HTML file. Added a div to try it out and same result.

body {
  background-color: aquamarine;
}
Temani Afif
  • 245,468
  • 26
  • 309
  • 415

3 Answers3

-1

In my experience, if you add any component or element inside , you would be offered a margin of 8px.

<body>
    <div style="background-color:red;height: fit-content;"></div>
</body>
Gautam
  • 46
  • 6
  • Hi Gautam, Thanks for your reply. Added a div to try it out and got same result. No whitespace. – Johanna Rodríguez Oct 19 '22 at 08:21
  • hey @Johanna sorry I missed _the white space_ part of the Question. In that case, you create a parent div and add a background to the element, which will produce the desired output. – Gautam Oct 19 '22 at 08:48
-2

I would check the height and width of the component you are trying to see. Make sure neither of them are 0.

UPDATE: I think I understand your question better now. If you want to see the 8px margin on the body set by default in Chrome, run this code snippet.

html {
  height: 100%;
}

body {
  height: 100%;
}

.example {
  background-color: aquamarine;
  height: 100%;
}
<html>
  <body>
    <div class='example'/>
  </body>
</html>
Fran
  • 102
  • 4
  • Thanks for your reply! It is just the background color on the body, no other component – Johanna Rodríguez Oct 19 '22 at 07:35
  • 1
    I think I misunderstood the question initially. If you are trying to see the 8px default margin set by the browser, try the code snippet I added to my answer in an update. – Fran Oct 19 '22 at 09:16
-2

Did you set both margin and padding to 0 in css?

You can style the body's margin to 8px if you would like to have the space without color or you can style the body's padding to 8px if you would like to get space color same as body background color.