Consider following code snippet:

<html>
<head>
<p>I like <span>HTML</span></p>
</head>
<body></body>
</html>
What will be displayed on page?
Explanation
The visible part of the HTML document should be located between <body> and </body>. So this current example of markup is not correct according to W3C. You should avoid using this, but this code will be rendered correctly.
In other words, you can use the following convenient elements inside of a header tag in HTML5: a, em, strong, code, cite, span, br, img.
Read more: Is it valid to have paragraph elements inside of a heading tag in HTML5 (P inside H1)?
Theory
  • Omitting the html, head, and body tags is certainly allowed by the HTML specs. The underlying reason is that browsers have always sought to be consistent with existing web pages, and the very early versions of HTML didn't define those elements. When HTML 2.0 first did, it was done in a way that the tags would be inferred when missing.
    In the HTML5 standard, the <html> tag, the <body> tag, and the <head> tag can be omitted. The following code will validate as HTML5:
    <!DOCTYPE html>
    <title>Page Title</title>
    <h1>This is a heading</h1>
    
    <p>
    This is a paragraph.
    </p>
    

    More details: Stackoverflow: Is it necessary to write HEAD, BODY and HTML tags?

@applefacelisa66 thanks. changed!

2017 Dec 1, 6:07:30 PM

the Theory part looks not related to the question....

2017 Nov 17, 1:32:07 AM

Explanation is wrong.

2016 Apr 19, 3:40:36 PM

+kuzzya, thanks! Yes, looks like that you are right! Modern browsers can handle such case and they will render properly this html code considering <p> block inside of <body>. Fixed right option.

2015 Oct 8, 9:29:38 PM

I am testing the code in Google Chrome Version 45.0.2454.101 (64-bit) (OS Ubuntu 14.04.3 LTS). Web browser displays "I like HTML"

2015 Oct 7, 6:46:02 AM

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Cosmo
Sign Up Now
or Subscribe for future quizzes