Having H1–H6 Doesn't Mean Your Heading Outline Works
When dealing with technical documentation or web content, a common misconception is that as long as there is in HTML <h1> to <h6> tag; the document structure is
If you maintain technical documentation or web pages, you may assume that a page with <h1> to <h6> tags already has a sound structure. Often it does not. Broken heading order, duplicate top-level headings, and fake headings built from <div> elements can all go unnoticed while the page looks fine.
These problems matter. They can break table-of-contents generation, weaken translation-memory matching, and make content harder to read with assistive technology. This guide explains why a heading tag alone proves little, how to check heading sequences with Beautiful Soup, and where automated checks must give way to human review.
Does having H1 to H6 tags mean your heading outline works? The short answer
No. A heading tag only shows that a heading is present, so you also need to check that your headings form a valid nested tree.
| Your situation | What to do | Why |
|---|---|---|
An <h1> is followed directly by an <h3> | Mark it as skip-level and check whether a level was left out on purpose | Skipped levels break the nesting that table-of-contents generation depends on |
A page has more than one <h1> | Mark it as multiple-h1 and have a person confirm it | A single-page application or a multilingual version may legitimately allow it |
Headings are built with <div class="title"> | Mark it as non-heading-title and leave it out of the tree unless you declare a conversion rule | A styled <div> is not a heading in the document structure |
| The headings look correct on screen | Check the markup itself, not the rendered result | CSS can make a <p> look like an H1 while the real <h2> renders in small type |
| The page is generated dynamically by a CMS or JavaScript | Pre-process it with a headless browser, or send the source for manual review | Beautiful Soup cannot obtain the complete DOM in these cases |
Why the tag alone doesn't prove structure
What the HTML rules expect
The HTML specification sets clear semantic rules for heading levels. Headings should be nested in sequence and should not skip levels. The presence of an <hN> tag does not guarantee this.
Real production environments often break the outline. Common causes include:
- CMS templates that insert headings at fixed levels
- Pasting from rich-text editors
- Front-end components that wrap content in ways nobody reviews
How visual styles can mislead you
The most misleading case is when CSS overrides the semantics. For example, a <p> styled with font-size: 24px looks like an H1, while a real <h2> may be rendered in small type.
If you rely only on regular expressions that match tag names, or on how the browser renders the page, you may mistake the visual hierarchy for the semantic hierarchy. Beautiful Soup parses the DOM tree itself and is not affected by CSS, so it can validate structure from the original markup.
Try it on synthetic examples
To illustrate the problem, the following sections use in-memory HTML fragments. These are synthetic examples built to demonstrate the logic. They do not represent real pages, and they do not correspond to any industry-standard thresholds.
A correct heading sequence
Correct input example
<h1>API 概览</h1>
<h2>认证机制</h2>
<h3>OAuth2 流程</h3>
<h2>错误处理</h2>
The expected output shows hierarchical continuity, no skipped levels, a single H1, and subheadings that sit strictly under their parent headings.
A sequence with errors
Error and boundary input example
<h1>用户指南</h1>
<h3>快速开始</h3> <!-- 跳过 H2 -->
<div class="section-title">高级配置</div> <!-- 非标题标签 -->
<h1>附录</h1> <!-- 第二个 H1 -->
This example contains three types of issues:
- Skipped levels, from H1 straight to H3
- Non-heading titles, where
<div>elements imitate headings - Multiple H1 tags
Label these as "skip-level," "non-heading-title," and "multiple-h1." Do not simply report an error or ignore the issue.
Note that <div class="section-title"> contains the word "title," but semantically it is not a heading. Leave it out of the hierarchical tree. If your business requirements treat it as a heading, declare a conversion rule explicitly and annotate it separately during acceptance testing.
Check structure with Beautiful Soup
The following Python example uses Beautiful Soup 4.15.0 with the standard library's html.parser. It builds a sample in memory and runs basic validation.
- Prepare the input. Assign the HTML string you want to inspect to the
html_snippetvariable. To read from a file, useopen().read()to get the string, then pass it to the parser. - Run the script in your own isolated dependency environment. Do not assume version compatibility without testing it.
- Read the output. The script prints a structured list of issues and uses assertions to confirm the known defects in the synthetic data.
The script does not depend on external networks or file system operations. Its assertions are based on the design expectations for the synthetic data.
from bs4 import BeautifulSoup
# 输入准备:合成示例包含跳级、伪标题、多H1
# 实际使用时可替换为 open('page.html').read()
html_snippet = """
<h1>用户指南</h1>
<h3>快速开始</h3>
<div class="section-title">高级配置</div>
<h1>附录</h1>
"""
soup = BeautifulSoup(html_snippet, 'html.parser')
headings = soup.find_all(['h1', 'h2', 'h3', 'h4', 'h5', 'h6'])
issues = []
prev_level = 0
h1_count = 0
for tag in headings:
level = int(tag.name[1])
text = tag.get_text(strip=True)
if level == 1:
h1_count += 1
if prev_level > 0 and level > prev_level + 1:
issues.append(f"skip-level: H{prev_level} -> H{level} at '{text}'")
prev_level = level
if h1_count != 1:
issues.append(f"multiple-h1: found {h1_count} H1 tags")
# 检查伪标题(仅作为补充信号,不自动纳入层级)
pseudo_titles = soup.find_all('div', class_='section-title')
if pseudo_titles:
issues.append(f"non-heading-title: {len(pseudo_titles)} div.section-title found")
# 输出与验收:针对本合成示例的预期断言
print("Detected issues:")
for issue in issues:
print(f"- {issue}")
assert len(issues) == 3, f"Expected 3 issues, got {len(issues)}"
assert any('skip-level' in i for i in issues)
assert any('multiple-h1' in i for i in issues)
assert any('non-heading-title' in i for i in issues)
Keep the scope of this script in mind:
- It checks structural anomalies at the tag level only. It does not assess content quality or visual consistency.
find_allreturns tags in document order, so hierarchy inference depends entirely on the state recorded during traversal.- To handle complex nesting, such as
sectionorarticlewrappers, you need to analyse parent nodes. This example covers only basic linear-sequence validation.
Acceptance criteria and where human review is needed
Code can catch mechanical errors, but it cannot replace human judgement about meaning. The table below lists typical observations, how they are handled automatically, and when a person needs to step in.
| Observation of the phenomenon | Automated processing | Necessity of human review | Note |
|---|---|---|---|
| H1→H3 jump level | Marks skip-level | High | Confirm whether this is a typographical error or an intentional omission of intermediate sections |
| Multiple H1 | Marks multiple-h1 | High | A single-page application or multilingual version may be legitimate |
div/span with a title class name | Marks non-heading-title | In | If it is a legacy template, it may need batch conversion to |
| H2 content is empty or consists solely of symbols | Does not detect | High | This is a content quality issue and falls outside structural validation |
| The title contains a link or an emphasis tag | Normal text extraction | Low | Processed with get_text(strip=True) |
These rules apply only to the validation logic of the current synthetic example. They are not a general specification. When you work with CMS-generated dynamic pages, Shadow DOM, or JavaScript-rendered content, Beautiful Soup cannot access the complete DOM. In those cases, pre-process the page with a headless browser or send the original source for manual review.
Translating documents with a checklist
Process the body text, links, code, and structure of a web document separately. Put the protected sections into your acceptance checklist, then assess the readability and visual presentation of the translated content.
OmniDoc translates PDF, Word, PowerPoint and Excel files: scanned pages are recognized first, table cells are translated one by one so tables keep their rows and columns, and a PDF comes back as both a bilingual and a translation-only file. Paid translation adds a glossary and context translation.
References and next steps
Next step: Choose an HTML document you are working on, run the validation script, and record the types of issues it detects. If you find untagged headings or complex nesting, extend the script to analyse parent containers, or go straight to manual review.
📊 At a glance
| Observation | Automated handling | Human review needed |
|---|---|---|
| H1 followed by H3 | Marked as skip-level | High |
| More than one H1 | Marked as multiple-h1 | High |
| H2 is empty or contains only symbols | Not detected | High |
| Title contains a link or emphasis tag | Normal text extraction | Low |
🎯 Which approach fits you?
If you maintain templates that generate headings
Run the structural check on sample pages from each template, then review any skipped levels and duplicate H1 tags before they spread.
If your pages are built by JavaScript or a CMS at runtime
Pre-process the pages with a headless browser before validating, or send the source for manual review, because Beautiful Soup cannot see the complete DOM.
If you translate web documents
Protect the code, links, and structure in your acceptance checklist, then check the translated text for readability and layout.
❓ FAQ
1. Does having H1 to H6 tags mean my page structure is correct?
No. A tag only shows that a heading exists. You also need to check that the headings are nested in sequence and do not skip levels.
2. Can CSS make a heading look right when its structure is wrong?
Yes. A styled <p> can look like an H1 while the real <h2> renders in small type. Check the markup itself, not the rendered result.
3. Should a <div> styled as a title count as a heading?
Not by default. The script labels it as non-heading-title and leaves it out of the tree. If your requirements treat it as a heading, declare a conversion rule and annotate it during acceptance testing.
4. Can the script handle complex nesting or dynamic pages?
Not fully. It covers basic linear-sequence validation at the tag level. For section or article wrappers, analyse parent nodes. For dynamic or JavaScript-rendered pages, pre-process them with a headless browser or send them for manual review.
📝 Summary
A heading tag alone does not prove that your outline works. Check the sequence of headings for skipped levels, duplicate H1 tags, and fake headings, and send the cases that need judgement to a person. Then check the translated output against the same checklist.
Try it now: upload a document and get it translated with the layout intact


