CSS renderiza tag BODY even without the TAG

Asked

Viewed 82 times

3

I have an HTML file which I have defined 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 css prompt. stylized as follows

*{margin:0; padding:0;} 

body{
    background:#000;
}

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

The point is, why did this happen ?

  • What’s the idea of having an HTML page without the tag <body>?

  • It’s not an idea, it turns out I forgot to put it. Then the doubt arose.

  • Current browsers already add the default tag.

1 answer

5


Even if it doesn’t add the tag <body> the browser tries to fill in what is missing from the document, that is even if I just do this in HTML:

<p>teste</p>

Will be generated something like (without doctype):

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

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

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

See the result:

Resultado

The test was on Opera, but it uses the same Chrome technology for rendering

I answered a similar question to the one about omitting tags:

  • 1

    Cool. Interesting to know that the browser influences directly on the code.

  • @Mauroalexandre believe that since IE5.5 and Mozilla Firefox 1 this already occurred, so all browsers do this, it will not be something to worry about ;)

  • 1

    When I was programming on the Etscape , in its first versions, it had never happened, since then it never happened, so I decided to take the doubt.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.