HTML Guide
The <section>
element can be used to define sections of a document, like chapters, tabbed content, etc. Consider using a heading element (any of <h2>
to </h6>
) to present each section. Example:
<h1>All about guitars</h1>
<section>
<h2>Guitar types</h2>
<p>Acoustic, electric, classical... we have them all!</p>
</section>
<section>
<h2>Amplifiers</h2>
<p>Analog, digital, portable...</p>
</section>
Related W3C validator issues
The <article> element can be used to define complete, self-contained compositions of a document, for example blog posts. Consider using a heading element (any of <h2> to </h6>) to present each article.
Example:
<h1>Our blog</h1>
<article>
<h2>How to validate accessibility</h2>
<p>Use Rocket Validator for a in-depth scan</p>
</article>
<article>
<h2>How to monitor sites for accessibility</h2>
<p>Define schedules in Rocket Validator</p>
</article>
The HTML <h1> to <h6> elements represent headings for the different sections of a document, where <h1> is the highest section and <h6> is the lowest. Headings are specially important on screen readers as they give a quick overview of the contents of the different sections in the web page, so although it’s technically correct (not an error) to use a <h1> in this way:
<section class="about">
<article>
<h1>Article heading</h1>
<p>Lorem</p>
</article>
</section>
this will raise a warning as it would be preferrable for example to leave the <h1> for the heading of the <section>, and <h2> for the heading of the article, like this:
<section class="about">
<h1>About heading</h1>
<article>
<h2>Article heading</h2>
<p>Lorem</p>
</article>
</section>
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.
The main element represents the dominant contents of the document, so it should not be contained within another section.
A document must not have more than one main element that does not have the hidden attribute specified.
A hierarchically correct main element is one whose ancestor elements are limited to html, body, div, form without an accessible name, and autonomous custom elements. Each main element must be a hierarchically correct main element.