HTML Guide
An <a> element has been found in an invalid place within a <table> element.
For example, the following code would cause this issue:
<table>
<tr>
<a href="#">link</a>
</tr>
</table>
Instead, the <a> element should be inside a <td> element, as a <tr> can’t hold content directly:
<table>
<tr>
<td>
<a href="#">link</a>
</td>
</tr>
</table>
An opening <body> tag has been found in an incorrect place. Check that it appears only once in the document, right after the closing </head> tag, and that the whole document content is contained within <body> and </body> tags.
A <br> element has been found in an invalid place within a <table> element.
For example, the following table has an invalid <br> between two <tr>, but the <br> that appears inside a <td> is valid.
<table>
<tr>
<th>Item</th>
<th>Description</th>
</tr>
<!-- The following br is invalid -->
<br>
<tr>
<td>Book</td>
<td>
<!-- The br in the following line is valid -->
Title: HTML & CSS<br>
Author: John Duckett
</td>
</tr>
</table>
A <button> tag can’t include other <button> tags inside. Most probable cause is an unclosed <button> tag, like in this example:
<button>Submit
<button>Cancel</button>
An opening <head> tag has been found in an incorrect place. Check that there’s only a <head> tag in the document.
This issue can happen because the expected closing tag </head> was misspelled as <head>, as in this example:
<!DOCTYPE html>
<html lang="">
<head>
<title>Test</title>
<head>
<body>
</body>
</html>
Or, it could happen because another <head>...</head> section was nested inside a previous one:
<!DOCTYPE html>
<html lang="">
<head>
<title>Test</title>
<head>
</head>
</head>
<body>
</body>
</html>
HTML documents are expected to start with a first line containing the Document Type Declaration, that defines the HTML version used. Since HTML5, it’s just <!DOCTYPE html>, which must appear before the start <html> tag.
Here’s an example of a minimal HTML5 document:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<p></p>
</body>
</html>
All HTML documents must start with a <!DOCTYPE> (Document Type Declaration), that informs browsers about the type and version of HTML used to build the document. In HTML5, this is simply <!DOCTYPE html> and must appear at the start of the document.
Here is an example of a minimal HTML document, including the Document Type Declaration at its start:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<p></p>
</body>
</html>
An end tag for X has been found that does not correspond to a previous open tag. This usually happens when you close the same tag twice, for example:
<ul>
<li>item</li>
</ul>
</ul>
A stray <br> happens when the <br> element, which is phrasing content, is placed in contexts that only allow specific children. Common mistakes include putting <br> directly inside <ul>, <ol>, <table>, <tr>, or outside <body>, and inserting it between block-level siblings to add spacing instead of using CSS. The validator flags this because it violates the HTML content model.
This matters for standards compliance, predictable rendering, and accessibility. Screen readers and assistive tech rely on correct structure (lists made of li, tables built from tr/td, sections within body). Misplaced <br> can produce confusing reading orders and inconsistent layout across browsers.
How to fix:
- Keep <br> only where phrasing content is allowed (typically inside text-flowing elements like p, span, li, td, caption).
- For spacing between blocks, use CSS margins instead of <br>.
- For lists, use proper li items; for tables, place text inside td/th; for forms, use grouping and CSS.
- Ensure no <br> appears outside <body> or inside elements that have restricted content models (ul, ol, table, tr, thead, tbody, tfoot, colgroup, select, dl directly, etc.).
- If a line break is purely presentational across viewports, consider CSS (display:block, white-space) instead of <br>.
Examples
Valid use inside phrasing content
<p>
First line.<br>
Second line.
</p>
Invalid: <br> directly inside a list (triggers the error)
<ul>
<br>
<li>Item 1</li>
<li>Item 2</li>
</ul>
Fix: remove the stray <br>; use list items only
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
Invalid: <br> outside <body> (triggers the error)
<!DOCTYPE html>
<html lang="en">
<head>
<title>Stray br Tag Example</title>
</head>
<br>
<body>
Content here.
</body>
</html>
Fix: move <br> inside the body (or use CSS if only spacing is needed)
<!DOCTYPE html>
<html lang="en">
<head>
<title>No Stray br Tag</title>
</head>
<body>
Content here.<br>
New line in body.
</body>
</html>
Invalid: <br> as a child of <table> (triggers the error)
<table>
<br>
<tr>
<td>A</td>
<td>B</td>
</tr>
</table>
Fix: use proper table rows and cells; place text inside cells
<table>
<tr>
<td>A</td>
<td>B</td>
</tr>
<tr>
<td>More A</td>
<td>More B</td>
</tr>
</table>
Invalid: using <br> for spacing between blocks (not allowed between siblings)
<div>Section A</div>
<br>
<div>Section B</div>
Fix: use CSS margins for spacing
<!DOCTYPE html>
<html lang="en">
<head>
<title>Spacing with CSS</title>
<style>
.block { margin-bottom: 1rem; }
</style>
</head>
<body>
<div class="block">Section A</div>
<div>Section B</div>
</body>
</html>
Valid alternatives where a break is needed in phrasing context
<li>
Address: 123 Main St.<br>
Suite 400
</li>
Tips:
- Use exactly <br> (no closing tag needed) and do not self-close as XML (<br />) unless your tooling requires it; both parse in HTML, but stick to HTML style for consistency.
- If you see multiple “stray start tag ‘br’” errors, check parent containers: fixing the first invalid parent often resolves many subsequent errors.
A <div> tag appears where the HTML structure does not expect it, often due to incorrect nesting or missing closing tags.
HTML elements must be properly nested and closed according to the specifications outlined by the HTML standard. A stray start tag usually occurs when a block-level element like <div> is used in a context where only phrasing (inline) content is permitted, or if required closing tags (such as </li>, </tr>, or </td>) are missing, causing the parser to be out of sync.
Incorrect Example: div after closing the html tag
<!DOCTYPE html>
<html lang="">
<head>
<title>Test</title>
</head>
<body>
<p></p>
</body>
</html>
<div>
some extra content
</div>
In the above, the <div> at the bottom is not valid because it appears after closing the html tag.
Always close elements properly and place block-level elements like <div> only inside appropriate containers. If your issue occurs elsewhere, look for missing closing tags or incorrect placement of the <div> relative to tables, lists, or other structural elements.
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>
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.
A stray start tag “link” error occurs when a <link> element appears outside the <head> section, for example after the document’s closing </html> tag.
The <link> element is used to reference external resources like stylesheets and must appear inside the document’s <head> section, before </head>.
Valid usage example:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Link Tag Example</title>
<link rel="stylesheet" href="css/app.css">
</head>
<body>
</body>
</html>
In this example, the <link> tag is correctly placed within the <head> element.
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>
A td (table cell) start tag must be placed inside a tr (table row) within a table.
The td element represents a cell of a table that contains data. According to HTML specifications, a td must be a child of a tr, which in turn must be a child of a table. Placing a td directly outside a tr or outside a table is invalid and causes the “stray start tag ‘td’” error in the W3C Validator.
Incorrect usage:
<table>
<td>Cell data</td>
</table>
In the above example, the td is not inside a tr.
Correct usage:
<table>
<tr>
<td>Cell data</td>
</tr>
</table>
Here, the td is nested inside a tr, which is correctly within a table. This will resolve the validation error.
A <td> or <th> element has a colspan attribute value that extends beyond the total number of columns defined in the <tbody> section.
HTML tables must have rows with a consistent number of columns within each <thead>, <tbody>, or <tfoot> group. If a cell uses the colspan attribute to span more columns than exist in the current row group, the table becomes semantically incorrect and fails validation.
Example of the Issue
<table>
<tbody>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
</tr>
<tr>
<!-- Invalid: colspan="3" but only 2 columns in tbody -->
</tr>
</tbody>
</table>
How to Fix
Ensure that the maximum number of columns in any row (considering colspan) within a <tbody> does not exceed the columns defined by the longest row in that group.
Corrected Example
<table>
<tbody>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
</tr>
<tr>
<td colspan="3">Spans all columns</td>
</tr>
</tbody>
</table>
Or, if you only need two columns:
<table>
<tbody>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
</tr>
<tr>
<td colspan="2">Spans two columns</td>
</tr>
</tbody>
</table>
Adjust the column count by either increasing the number of cells in each row or reducing the value of colspan as appropriate for your table structure.
Ensure each column in your table has at least one <td> or <th> cell starting in it. This error often occurs when using the colspan or rowspan attributes incorrectly.
Example of correct usage:
<table>
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>Row 1, Cell 1</td>
<td>Row 1, Cell 2</td>
</tr>
<tr>
<td>Row 2, Cell 1</td>
<td>Row 2, Cell 2</td>
</tr>
</table>
Incorrect usage example:
<table>
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td colspan="2">Row 1, Cell 1</td>
</tr>
<tr>
<td>Row 2, Cell 1</td>
<!-- Missing cell in column 2 -->
</tr>
</table>
The corrected version ensuring each column has a starting cell:
<table>
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td colspan="2">Row 1, spanning both columns</td>
</tr>
<tr>
<td>Row 2, Cell 1</td>
<td>Row 2, Cell 2</td>
</tr>
</table>
A <table> contains an incoherent number of cells on one of its columns. Check the structure of the table to find the invalid column.
Example of a valid table that defines in its header that the first column is 2 cells wide:
<table>
<thead>
<tr>
<th colspan="2">The table header</th>
</tr>
</thead>
<tbody>
<tr>
<td>The table body</td>
<td>with two columns</td>
</tr>
</tbody>
</table>
This same table with an empty body will be invalid because the table header cannot match any body columns:
<table>
<thead>
<tr>
<th colspan="2">The table header</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
A <table> contains an incoherent number of columns on one of its rows. Check the structure of the table to find the invalid row.
For example, in the following table, the first <tr> row defines that it’s 2 columns wide, but the second <tr> row tries to use 5 columns by means of a colspan attribute:
<table>
<!-- This first row sets the table as 2 columns wide -->
<tr>
<td>First</td>
<td>Second</td>
</tr>
<!-- This second row tries to use 5 columns -->
<tr>
<td colspan="5">Wrong</td>
</tr>
</table>
A td element must be placed within a tr (table row) element, not directly as a child of tbody, thead, tfoot, or table.
The td (table cell) element defines a cell of a table that contains data. According to the HTML standard, td elements must be placed inside tr elements, which are used to group table cells in a row. Directly placing a td element inside tbody, thead, tfoot, or table violates the HTML content model and will cause a validation error.
Incorrect example:
<table>
<tbody>
<td>Cell 1</td>
<td>Cell 2</td>
</tbody>
</table>
Correct example:
<table>
<tbody>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
</tr>
</tbody>
</table>
Always wrap td elements within a tr when constructing table rows.
<iframe> tags are used to embed another document within the current document. To indicate the contents of that nested document, you can either use the src attribute with an URL, or directly provide the contents with the srcdoc attribute. Examples:
<!-- This will embed a document by its URL -->
<iframe src="https://example.com"></iframe>
<!-- This will embed the contents provided in the srcdoc attribute -->
<iframe srcdoc="<p>some content</p>"></iframe>
<!-- This is invalid -->
<iframe><p>some content</p></iframe>
Direct text nodes inside select are not permitted content. Browsers typically ignore or mangle that text, leading to inconsistent rendering and confusing experiences for screen reader users. It also breaks conformance, which can impact maintainability and automated tooling. The right approach is to keep instructional text in a corresponding label, or provide a non-selectable prompt using a disabled, selected option. Group labels must be provided with optgroup elements, not free text.
To fix it, remove any raw text inside the select. If you need a prompt, add a first option with value="" and disabled selected hidden for a placeholder-like experience, or rely on a visible label. Ensure all selectable items are wrapped in option, and any grouping uses optgroup with its label attribute. Always associate the select with a label via for/id for accessibility.
Examples
Triggers the error (text node inside select)
<select>
Please select an option:
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
Correct: move instructions to a label
<label for="flavor">Please select a flavor:</label>
<select id="flavor" name="flavor">
<option value="vanilla">Vanilla</option>
<option value="chocolate">Chocolate</option>
</select>
Correct: provide a non-selectable prompt inside select
<label for="country">Country</label>
<select id="country" name="country" required>
<option value="" disabled selected hidden>Select a country</option>
<option value="us">United States</option>
<option value="ca">Canada</option>
</select>
Correct: use optgroup for grouping, not free text
<label for="city">City</label>
<select id="city" name="city">
<optgroup label="USA">
<option value="nyc">New York</option>
<option value="la">Los Angeles</option>
</optgroup>
<optgroup label="Canada">
<option value="toronto">Toronto</option>
<option value="vancouver">Vancouver</option>
</optgroup>
</select>
Correct: full document (for context)
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Select without stray text</title>
</head>
<body>
<form>
<label for="size">Choose a size:</label>
<select id="size" name="size">
<option value="" disabled selected hidden>Select a size</option>
<option value="s">Small</option>
<option value="m">Medium</option>
<option value="l">Large</option>
</select>
</form>
</body>
</html>
Tips:
- Put instructions in a label or surrounding text, not inside select.
- Every choice must be an option; use optgroup with label to name groups.
- For placeholders, prefer a disabled, selected first option; avoid raw text nodes.