CSS renders BODY tag even without the TAG existing

3

I have an HTML file which I set as follows

<!DOCTYPE html>
<html lang="pt-br">
    <head>
        <title>Prompt</title>
        <meta charset="UTF-8" />
        <link rel="stylesheet" href="style/prompt.css" type="text/css">
    </head>
</html>

In my file prompt.css I stylized as follows

*{margin:0; padding:0;} 

body{
    background:#000;
}

As a result, the browser interpreted that the TAG BODY existed and left the background in BLACK, as defined in the css.

The question is, why did this happen?

    
asked by anonymous 29.10.2016 / 18:01

1 answer

5

Even though I do not add the <body> tag, the browser tries to fill in what's missing from the document, even if I do just this in HTML:

<p>teste</p>

It will be generated something like (without doctype):

<html>
<head>
<title></title>
</head>
<body>
<p>teste</p>
</body>
</html>

Maybe you have not noticed <body> , because when we use HTML5 doctype the height of default <body> will be zero, so just add a height: 100% you will notice that <body> was generated:

<!DOCTYPE html>
<html>
<head>
    <style>
        body {
            background-color: #f00;
            height: 100%;
        }
    </style>
</head>
</html>

See the result:

  

ThetestwasinOpera,butitusesthesametechnologyasChrometorender

Iansweredasimilarquestiontothisonethattalkedaboutskippingthetags:

  • link
29.10.2016 / 18:38