HTML Guide
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.
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> 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>
<td colspan="3">Too wide</td> <!-- 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>
This W3C HTML Validator issue indicates that you’ve placed text content directly inside a <select> element. According to the HTML specification, a <select> element can only contain <option> or <optgroup> elements, and no direct text nodes.
Here’s how to resolve this issue:
Steps to Fix:
- Remove Text Nodes: Ensure that you remove any text that exists directly inside the <select> tags.
- Use <option> Elements: If you want to display text as an option, use <option> tags for each selectable item.
Example of Incorrect Usage:
Here’s an example that generates the validator issue:
<select>
Please select an option:
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
Corrected Example:
Here’s how to correct this by moving the text outside of the <select> element:
<label for="options">Please select an option:</label>
<select id="options">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
Summary:
- Always wrap any instructional or descriptive text outside of the <select> element.
- Use <option> tags to define the choices within the <select>.
The <ul> element is used to define unordered lists, where each element must be contained within a <li> element, like in this example:
<ul>
<li>first element</li>
<li>second element</li>
<li>third element</li>
</ul>
Ensure that there’s no content inside the <ul> element that is not contained within a <li> element.
Sometimes this error comes when trying to give a title to the list, for example:
<ul>
Fruits
<li>Apple</li>
<li>Orange</li>
</ul>
Instead, that title text should be outside the list, like:
<span>Fruits</span>
<ul>
<li>Apple</li>
<li>Orange</li>
</ul>
Other times, this can come as the concatenation of <li> elements which results in something like:
<ul>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ul>
Note how in this case that used to join the <li> is causing the problem, as it’s content that is not contained by a <li> element, as required by the <ul> element.
Read about Normalization in HTML and CSS.
The <th> HTML element defines a cell as a header of a group of table cells, and must appear within a <tr> element.
In the following example for a simple table, the first <tr> contains two <th> header cells naming the values for each column:
<table>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>Liza</td>
<td>49</td>
<tr>
<tr>
<td>Joe</td>
<td>47</td>
</tr>
</table>
The old <acronym> element in previous versions is now obsolete, in HTML5 you must use <abbr> instead.
<td> elements no longer accept an align attribute. This can be achieved using CSS like this:
<td style="text-align:center;">content</td>
The aria-controls attribute identifies an element or elements in the same document whose contents or presence are controlled by the current element. It must point to existing elements by their ID. Check that the IDs contained in that property exist within the same document.
ARIA can express semantic relationships between elements that extend the standard parent/child connection, such as a custom scrollbar that controls a specific region, for example:
<div role="scrollbar" aria-controls="main"></div>
<div id="main">
. . .
</div>
The aria-describedby attribute is used to indicate the IDs of the elements that describe the object. It should reference an existing ID on the same document, but that id was not found.
The aria-hidden attribute is redundat on an input of type hidden, so it should be removed.
Example:
<!-- Instead of this... -->
<input type="hidden" aria-hidden="true" id="month" value="10" />
<!-- You can just use this -->
<input type="hidden" id="month" value="10" />
The aria-hidden attribute is not allowed on the link element according to HTML and ARIA specifications.
aria-hidden is a global ARIA attribute used to hide elements from assistive technologies such as screen readers. However, it is not permitted on some elements, including the link element, because link is a void element intended for non-visible resources like stylesheets and icons.
Incorrect usage:
<link rel="stylesheet" href="styles.css" aria-hidden="true">
Correct usage (simply remove aria-hidden):
<link rel="stylesheet" href="styles.css">
If your intent is to control screen reader visibility, apply aria-hidden to visible content elements like <div>, <span>, or <img>—not to metadata elements such as <link>.
The aria-labelledby attribute establishes relationships between objects and their label(s), and its value should be one or more element IDs. It should reference an existing ID on the same document, but that id was not found.
The aria-owns attribute contains an ID reference that does not match any element in the same document.
According to the ARIA specification and the WHATWG HTML standard, the value of the aria-owns attribute must be a space-separated list of IDs of elements that exist in the same DOM document. This attribute is meant to modify the accessibility tree by creating relationships not present in the DOM structure, but all referenced elements must be part of the same document. If an ID in the aria-owns attribute does not match any element, is in another document (such as an iframe), or contains a typo, validation will fail.
Common reasons for this issue:
- Referencing a nonexistent ID.
- Referencing an ID from another document (e.g., across iframes).
- Typos in the ID value.
Correct usage:
<div id="container" aria-owns="owned-element">
<p>Container</p>
</div>
<div id="owned-element">
<p>Owned by container (in accessibility tree)</p>
</div>
Incorrect usage (missing or cross-document ID):
<div id="parent" aria-owns="child"></div>
<!-- Missing <div id="child"> or 'child' exists in a different frame/document -->
To fix the issue, ensure that all IDs referenced in aria-owns correspond to elements present in the same document.
Complete valid example:
<!DOCTYPE html>
<html lang="en">
<head>
<title>aria-owns Example</title>
</head>
<body>
<div id="menu" aria-owns="item1 item2">
Main menu (accessibility tree owner)
</div>
<div id="item1">
Menu item 1
</div>
<div id="item2">
Menu item 2
</div>
</body>
</html>