Stray start tag

Sometimes, if you try to validate your HTML code, you can get lot’s of error if your HTML code is not well structured. Sometimes it occurred when some unique tag appears multiple time in your document i.e. <code data-enlighter-language="generic" class="EnlighterJSRAW"><HTML>, <head>, <body>. So let’s check some example to understand them. Check the basic HTML structure here.

Stray start tag “html”

The <html> is a parent container tag. It should appears once in a whole document.

Stray start tag
<!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 html validator and you can get lot’s 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 element body 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.

About Ashis Biswas

A web developer who has a love for creativity and enjoys experimenting with the various techniques in both web designing and web development. If you would like to be kept up to date with his post, you can follow him.

Leave a Comment