HTML Guides for parsing
Learn how to identify and fix common HTML validation errors flagged by the W3C Validator — so your pages are standards-compliant and render correctly across every browser. Also check our Accessibility Guides.
When the validator parses your HTML (especially in XHTML mode or when serialized as XML), every element name must conform to the XML 1.0 naming rules. These rules require that element names begin with a letter (a–z, A–Z) or an underscore (_), followed by any combination of letters, digits, hyphens (-), underscores, periods (.), or combining characters. Characters like spaces, angle brackets, slashes, or other special symbols within a tag name make it unrepresentable in XML 1.0.
This error most commonly occurs due to:
- Typos in tag names — accidentally inserting a space, extra character, or symbol into a tag name.
- Malformed closing tags — forgetting the slash or placing characters incorrectly in a closing tag.
- Template syntax errors — template engine placeholders leaking into the final HTML output.
- Copy-paste issues — invisible or non-ASCII characters sneaking into tag names from rich-text editors.
This matters because browsers may not parse malformed tags as intended, leading to broken layouts or missing content. Screen readers and assistive technologies rely on well-formed markup to interpret page structure. Additionally, any system that processes your HTML as XML (such as RSS feed generators, EPUB renderers, or XHTML-serving environments) will reject documents with invalid element names entirely.
How to Fix
- Inspect the flagged line — look carefully at the element name the validator is complaining about. Check for stray characters, spaces, or symbols.
- Correct any typos — replace the malformed tag with the correct HTML element name.
- Validate template output — if you use a templating engine, ensure the rendered HTML doesn’t contain unprocessed template tokens inside tag names.
- Check for invisible characters — paste the tag name into a plain-text editor or use a hex viewer to spot hidden characters.
Examples
Typo with a space in the tag name
A space inside the tag name creates an invalid element name:
<!-- Wrong: space in the element name -->
<di v class="container">
<p>Hello world</p>
</di v>
Fix by removing the accidental space:
<!-- Correct -->
<div class="container">
<p>Hello world</p>
</div>
Special character in a tag name
An accidental special character makes the name unrepresentable in XML 1.0:
<!-- Wrong: stray hash character in the tag name -->
<s#ection>
<h2>About</h2>
</s#ection>
Fix by using the correct element name:
<!-- Correct -->
<section>
<h2>About</h2>
</section>
Malformed closing tag
A missing or misplaced slash can produce a garbled tag name:
<!-- Wrong: slash is in the wrong place -->
<p>Some text<p/>
Fix with a properly formed closing tag:
<!-- Correct -->
<p>Some text</p>
Template placeholder leaking into output
Unprocessed template syntax can produce invalid element names in the rendered HTML:
<!-- Wrong: unresolved template variable in element name -->
<{{tagName}}>Content</{{tagName}}>
Ensure your template engine resolves the variable before serving the HTML. The rendered output should be:
<!-- Correct: after template processing -->
<article>Content</article>
Ready to validate your sites?
Start your free trial today.