HTML Guide
A <head>
start tag has been found in an unexpected place in the document structure. Check that the <head>
section appears before the <body>
section, and that is not duplicated.
The <head>
section of an HTML document is the container of metadata about the document, and must appear before the <body>
section. A common cause of this issue is duplicated <head>
sections.
Here is an example of a minimal HTML document structure:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<p></p>
</body>
</html>
Related W3C validator issues
A stray start tag <html> has been found in the document. As this tag defines the start of the whole HTML document, it should appear only once.
The “Stray start tag noscript“ error in the W3C HTML Validator indicates that the <noscript> tag has been used incorrectly or is placed in an invalid location within your HTML document.
The <noscript> tag is used to define alternative content for users who have disabled JavaScript in their browsers or for browsers that do not support JavaScript.
Common Causes:
- Position of <noscript>: The <noscript> tag should be placed correctly within sections where it is allowed.
- Nested Improperly: The <noscript> tag should not be placed inside other tags where it is not valid.
Correct Usage:
-
Within <head>:
<head> <title>Example Page</title> <script> // Some JavaScript code </script> <noscript> <style> /* Alternative styling if JavaScript is disabled */ </style> </noscript> </head>
-
Within <body>:
<body> <h1>Welcome to the Example Page</h1> <script> // Some JavaScript code </script> <noscript> <p>JavaScript is disabled in your browser. Please enable JavaScript for the full experience.</p> </noscript> </body>
Fixing the Issue:
-
Inside Existing Tags: Ensure the <noscript> tag is not placed inside other tags where it cannot be parsed correctly.
<!-- Incorrect --> <div> <noscript> <p>JavaScript is disabled in your browser.</p> </noscript> </div> <!-- Correct --> <noscript> <div> <p>JavaScript is disabled in your browser.</p> </div> </noscript>
-
Placement in Body or Head: Verify that the <noscript> tag is placed inside the <body> or <head> based on what content it’s providing a fallback for.
<!-- Incorrect (inside an illegal tag) --> <div> Some content <noscript><p>JavaScript is disabled in your browser.</p></noscript> </div> <!-- Correct --> <div>Some content</div> <noscript><p>JavaScript is disabled in your browser.</p></noscript>
Summary:
- Place <noscript> only within accepted sections (<head> or <body>).
- Avoid nesting <noscript> inside other tags improperly.
A <script> start tag has been found in an unexpected place in the document structure. Check that the <script> section appears within the <head> or <body> sections.
Here’s an example of a script inserted in the head of the document:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script>
console.log("Hello from the head");
</script>
</head>
<body>
<p></p>
</body>
</html>
The “Stray start tag “section”” error in the W3C HTML Validator typically occurs when a <section> tag appears in an unexpected location within your HTML document structure. This can happen if the <section> tag is not positioned correctly within the HTML5 content model.
Here’s a focused guide to fix this issue:
1. Check the Parent Element
Make sure the <section> tag is placed within elements where it is allowed. According to the HTML5 specification:
- A <section> element should be placed within the <body> tag.
- It should not be a direct child of an inline element or an element that does not support flow content.
2. Correct Nesting Within Elements
Ensure your HTML structure follows a logical hierarchy and that the <section> element is not incorrectly nested. This example shows a correct usage of the <section> tag:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Correct Usage of Section</title>
</head>
<body>
<header>
<h1>Page Title</h1>
</header>
<nav>
<!-- Navigation links -->
</nav>
<main>
<section>
<h2>Section Title</h2>
<p>Content for the first section.</p>
</section>
<section>
<h2>Another Section Title</h2>
<p>Content for the second section.</p>
</section>
</main>
<footer>
<p>Footer content</p>
</footer>
</body>
</html>
3. Check for Mistaken Hierarchy
Verify whether the <section> tag is mistakenly placed inside elements that do not support it, such as directly inside a <p> tag or other inline elements. Correct any incorrect usage. For example this is incorrect usage because the <section> tag is placed after the closing <body> tag:
Incorrect:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Sample page</title>
</head>
<body>
<h1>Main title</h1>
<p>Some content</p>
</body>
</html>
<section>
<h2>Incorrect Section</h2>
<p>This section should not be after the closing body tag.</p>
</section>
Correct:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Sample page</title>
</head>
<body>
<h1>Main title</h1>
<p>Some content</p>
<section>
<h2>Correct Section</h2>
<p>This section is fine.</p>
</section>
</body>
</html>
Summary
- Ensure your <section> tags are used within the <body> tag and other allowed elements.
- Maintain a logical hierarchy in your HTML document.
- Avoid placing <section> tags inside inline elements like <p>.
Following these steps should resolve the “Stray start tag “section”” error in your HTML document. Validate your HTML again after making these corrections to ensure the issue is resolved.
A <style> start tag has been found in an unexpected place in the document structure. Check that the <style> section appears within the <head> section.
Although in general it’s better to put your styles in external stylesheets and apply them using <link> elements, CSS styles can also be included inside a document using the <style> tag. In this case, it should be placed within the <head> section, like in this example:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<style>
p {
color: #26b72b;
}
</style>
</head>
<body>
<p>This text will be green.</p>
</body>
</html>
There is an iframe tag inside a noscript tag that is itself inside the head section of the HTML document. This is not allowed because an iframe cannot be nested inside the head section.
To fix this issue, you may move the noscript section that contains the iframe tag outside of the head section, and ensure that it is placed within the body section of the HTML document.
For example, this is invalid HTML because the head section cannot contain iframe elements:
<!DOCTYPE html>
<html lang="en">
<head>
<title>My webpage</title>
<noscript>
<p>Please enable JavaScript to view this website</p>
<iframe src="https://example.com/"></iframe>
</noscript>
<!-- Other meta tags and styles go here -->
</head>
<body>
<!-- Rest of your webpage content goes here -->
</body>
</html>
Moving the noscript inside the body section fixes the issue, as that’s where iframe elements belong:
<!DOCTYPE html>
<html lang="en">
<head>
<title>My webpage</title>
<!-- Other meta tags and styles go here -->
</head>
<body>
<noscript>
<p>Please enable JavaScript to view this website</p>
<iframe src="https://example.com/"></iframe>
</noscript>
<!-- Rest of your webpage content goes here -->
</body>
</html>
The <head> section of an HTML document contains metadata about the document, and as a minimum it must include a <title> tag defining the document title.
Common causes for this issue are forgetting to define the <title>, or duplicated <head> sections where one of them does not include the title.
Here’s an example of a minimal HTML document including the title:
<!DOCTYPE html>
<html>
<head>
<title>Don't panic! This is the title</title>
</head>
<body>
<p></p>
</body>
</html>
And end tag has been found that does not match the current open element. Check the context to fix the start and end tags.
<meta> tags, used for defining metadata about HTML documents, must appear within the <head>...</head> section, but it has been found out of place. Check the document structure to ensure there are no <meta> tags outside the head section.
A common cause of this issue is having a duplicated, out of place <head>...</head> section. Ensure that this section appears in its proper place and is the only container for <meta> tags.
An <a> tag can’t include other <a> tags inside. Most probable cause is an unclosed <a> tag, like in this example:
<a href="one.html">Page 1
<a href="two.html">Page 2</a>