HTML Guide
Malformed comment syntax has been found, check out the affected comment.
HTML comments are helpful to leave notes about the code right next to it. To create a comment, it must start with <!--
and end with -->
, as in this example:
<!-- Good comment -->
<!--
Comments can
be multi-line
-->
A common cause for a malformed comment is using too many hyphens (-
) as in this example:
<!-- Wrong comment -->
Related W3C validator issues
XML 1.0 names, typically used for the id attribute of elements, must comply with specific constraints, such as:
- Must start with a letter or underscore _
- Subsequent characters can be letters, digits, hyphens -, underscores _, and periods .
- Cannot contain any spaces or special characters
Here’s an example of an invalid name for an ID:
<svg>
<g id="Group 270">
<!-- Content inside the group element -->
</g>
</svg>
This can be fixed by avoiding whitespace inside the name, like this:
<svg>
<g id="group-270">
<!-- Content inside the group element -->
</g>
</svg>
In this example, the id attribute value Group 270 has been changed to group-270 to follow the rules for XML 1.0 names.
Nested comments are not allowed in HTML. When you place an opening comment tag <!-- within an existing comment, it causes a parsing error.
To fix this issue, you should avoid nesting comments. If you need to include multiple comments in your HTML code, you can separate them or consider alternative ways to convey the information without nested comments.
Here’s an example of a nested comments, which is not allowed in HTML:
<!-- This is a valid comment -->
<!-- This <!-- is not allowed --> nested comment -->
To fix the nested comment issue, you can rewrite the comments like this:
<!-- This is a valid comment -->
<!-- Avoid nesting comments and provide comments separately -->
<!-- Another comment here -->