HTML Guides for trailing hyphen
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.
XML 1.0 doesn't allow a comment to end with a hyphen, and in HTML pages this usually comes from PHP code that never ran or from a comment typed with single hyphens, such as <!- note ->.
When the HTML parser meets <?, or <! without -- or DOCTYPE after it, or </ followed by something other than a letter, it reads everything up to the next > as a "bogus comment". If the character right before that > is a hyphen, the comment text ends with -. Browsers don't mind, but an XML 1.0 comment can't end that way, so the validator flags it. Look for an error at the same spot, such as Bogus comment. or one about XML processing instructions. Fixing that error clears this warning too.
PHP that reaches the browser without being run is a typical source, because its -> operator puts a - right before a >. If the server sends <?php echo $page->title; ?> as is, the bogus comment starts at <? and stops inside ->. The rest of the code, title; ?>, shows up on the page as plain text. Check that the server runs the file through PHP (usually it needs a .php extension) and that PHP is enabled for that directory. If the code is meant to be shown on the page, as in a tutorial, escape the < as <.
The other usual source is a comment typed as <!- note -> with single hyphens. HTML comments open with <!-- and close with -->.
Invalid example
<!- Main navigation ->
<nav>
<a href="/">Home</a>
</nav>
<h1><?php echo $page->title; ?></h1>
Valid example
<!-- Main navigation -->
<nav>
<a href="/">Home</a>
</nav>
<h1>About us</h1>
Validate at scale.
Ship accessible websites, faster.
Automated HTML & accessibility validation for large sites. Check thousands of pages against WCAG guidelines and W3C standards in minutes, not days.
1K Weekly
1,000 monthly checks. Cancel anytime.
Get 1K Weekly →Join teams across 40+ countries