HTML Guide for noscript
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>
A start tag for <img> has been found inside a <noscript> section within the <head>, where it’s not allowed. Consider moving it to the <body> section.
The HTML <noscript> element defines a section of HTML to be inserted if a script type on the page is unsupported or if scripting is currently turned off in the browser.
When JavaScript is disabled, the content inside <noscript> will be used instead, so this content must fit within its parent section. As an <img> tag is not allowed inside <head>, this will raise an issue. Instead, consider moving the <noscript> part to the <body> section.
This issue is often related to 3rd party tracking pixels like the Facebook or LinkedIn conversion tracking pixels. For example, the Facebook pixel instructions tell you to insert it like this:
<html>
<head>
<script>
...some script...
</script>
<noscript>
<img src="..." />
</noscript>
</head>
<body>
...
</body>
</html>
Instead, consider moving the <noscript> part inside the <body>, where the <img> makes sense to be inserted:
<html>
<head>
<script>
...some script...
</script>
</head>
<body>
...
<noscript>
<img src="..." />
</noscript>
</body>
</html>
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.