HTML Comment Remover
Remove lexical HTML comments while preserving comment-like text inside script, style, title, and textarea elements.
Description
HTML comments can be removed from source without deleting comment-like strings inside recognized raw-text elements.
When to use HTML Comment Remover
Use this tool to remove lexical HTML comments while preserving comment-like text inside script, style, title, and textarea elements.
Paste the HTML source to transform. Compare the returned source or text with the input using the lexical rules below.
How to use HTML Comment Remover and understand its results
- Paste the HTML source to transform. Compare the returned source or text with the input using the lexical rules below.
- Enter html using the field table and calculation rules, then run the tool.
- Read html. The explanation below defines the units, signs, ordering and any flags or placeholder values.
- If the tool reports an input issue, correct the values and run it again. Apply the stated assumptions when interpreting a successfully returned result.
| Input field | Meaning | Value type; see rules below | Requirement |
|---|---|---|---|
| html | HTML source. | string; maximum length: 1000000 | Required |
Paste HTML source. Scan with the shared tokenizer and discard comment tokens, preserving all other source tokens. Script, style, title, textarea, xmp, iframe, noembed and noframes are treated as raw-text contexts. An unterminated comment outside those contexts consumes the remaining source and is removed.3, 4
html=join(tokens whose kind is not comment) Units, indexing, boundary conditions and exceptional cases are defined in the calculation rules above.
| Output field | Meaning | Value type |
|---|---|---|
| html | Source with lexical comments removed. | string; maximum length: 1000000 |
{
"input": {
"html": "<p>A</p><!-- hidden --><p>B</p>"
},
"output": {
"html": "<p>A</p><p>B</p>"
}
} Limitations and assumptions
No browser DOM, CSS or JavaScript semantics are evaluated. Malformed source follows scanner rules, and comment removal is not sanitization.
Numeric inputs must be finite. Follow the calculation-specific rules for overflow, underflow and exceptional cases. Extremely large text inputs are rejected. Missing required fields, extra fields, wrong value types and violations of the calculation rules are input errors.
Alternative or Complementary methods
Use HTML Whitespace Collapser: Collapse ASCII whitespace in lexical text nodes while preserving tags, attributes, comments, and preformatted or raw-text element contents. For a complementary task, use HTML Tag Stripper: Remove lexical HTML tags, comments, and declarations while retaining raw text and character references; the result is not sanitized markup.
Further background: HTML Standard: Tokenization.
References
-
HTML Comment Remover — tool.io
-
HTML Standard: Tokenization — WHATWG
-
HTML Tag Counter — tool.io
-
HTML Attribute Parser — tool.io
Similar or alternative tools
- HTML Whitespace Collapser
Collapse ASCII whitespace in lexical text nodes while preserving tags, attributes, comments, and preformatted or raw-text element contents.
- HTML Tag Stripper
Remove lexical HTML tags, comments, and declarations while retaining raw text and character references; the result is not sanitized markup.