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.

HTML comments can be removed from source without deleting comment-like strings inside recognized raw-text elements. The distinction depends on lexical context.1, 2

Remove lexical HTML comments while preserving comment-like text inside script, style, title, and textarea 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

  1. Paste the HTML source to transform. Compare the returned source or text with the input using the lexical rules below.
  2. Enter html using the field table and calculation rules, then run the tool.
  3. Read html. The explanation below defines the units, signs, ordering and any flags or placeholder values.
  4. 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 fieldMeaningValue type; see rules belowRequirement
htmlHTML source.string; maximum length: 1000000Required

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 fieldMeaningValue type
htmlSource with lexical comments removed.string; maximum length: 1000000
json
{
  "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

  1. HTML Comment Remover — tool.io

  2. HTML Standard: Tokenization — WHATWG

  3. HTML Tag Counter — tool.io

  4. 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.

Don't forget to set a bookmark for tool.io!
Privacy | Imprint | Cookies