Sometimes, if you try to validate your HTML code, you can get lots of errors in your HTML code is not well structured. Sometimes it occurred when some unique tag appears multiple times in your document i.e. <HTML>, <head>, <body>. So let’s check some examples to understand them. Check the basic HTML structure here.
Stray start tag “html”
The <html>
is a parent container tag. It should appear once in a whole document.
<!DOCTYPE html>
<html>
<body>
<head>
<title>Test</title>
</head>
<p></p>
</body>
</html>
Stray start tag “head”
Generally appears before the <body> tag. But if we write multiple <head> tag or <head> tag outside the <body> tag, we can get the above validation error. Check the below code to get the idea.
<!DOCTYPE html>
<html>
<body>
<head>
<title>Test</title>
</head>
<p></p>
</body>
</html>
Now check the below code in the HTML validator and you can get lots of errors.
<!DOCTYPE html>
<html>
<body>
<head>
<title>Test</title>
</head>
<p></p>
</body>
</html>
<HTML>
<p>Demo</p>
- Element
<head>
is missing a required instance of the child element<title>
. It means the<head>
tag is not present after the<body>
tag. - Stray start tag
head
. Already discussed above. - Element
title
not allowed as a child of elementbody
in this context. That means we can’t use<title>
inside<body>
. - Stray start tag
p
. Here the<p>
tag is outside the<body>
tag.