Search code examples
htmlcssviewport

difference between html tag and body tag


I have a question, in this picture, I applied the background-color property to the html and body tags, but whats the difference in applying it to each one individually? Also, when I use the cursor tool to view the page's box model, I can see that both, the html and body tags end with the div element, but the background-color:green covers the entire viewport. Do you know why?

image


Solution

  • In the absence of a background on the html element, the body background will cover the page. If there is a background on the html element, the body background behaves just like any other element.