ForHosting KIT · Text & AI

Remove HTML comments

Clear draft notes and disabled fragments out of your HTML: a page with two comments comes back with both gone and a count of 2, while tags, indentation and line breaks around them stay exactly as written. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon

This HTML comment remover strips every complete comment block from supplied markup and returns both the cleaned text and the number of comments removed. It is useful when comments contain draft notes, build annotations, disabled fragments, or internal reminders that should not travel with published HTML. The operation is deterministic: everything outside comment delimiters remains exactly as provided, while an unfinished comment produces a clear input error instead of silently deleting the rest of the document.

Clean markup without reformatting it

Many HTML cleanup tools parse and serialize a document, which can reorder attributes, normalize whitespace, alter quoting, or repair malformed tags. That behavior is useful for some jobs, but it is unnecessary when the only goal is to remove comments. This capability performs a focused textual operation.

It scans for an opening HTML comment delimiter, copies everything before it unchanged, skips through the matching closing delimiter, and then continues from the next character. Text, tags, indentation, line endings, entities, template expressions, and attribute formatting outside comments are preserved exactly. The result therefore works well in source-control pipelines where a broad formatter would create distracting diffs.

If there are no comments, the original text is returned unchanged and the count is zero, making the operation safe to include as a routine preprocessing step even when input files vary from one run to another.

Understand comment boundaries and errors

An HTML comment begins with the exact sequence <!-- and ends at the next exact sequence -->. Everything between those delimiters is removed, including embedded tags, line breaks, punctuation, and strings that resemble another opening delimiter. This follows the practical boundary needed for deterministic stripping rather than attempting to interpret the removed material as active markup.

A closing sequence that appears without an earlier opening sequence is ordinary text and remains untouched. By contrast, an opening delimiter without a later closing delimiter is ambiguous and dangerous: treating it as a comment through the end of the input could erase genuine page content. No partial result is returned.

This strict behavior is especially valuable in automated publishing, because a damaged template stops visibly instead of producing a deceptively successful but truncated document. Fix the missing closing delimiter and submit the complete text again.

Use the count in dependable workflows

The removal count turns a simple text transformation into an auditable pipeline step. A deployment script can require zero comments in final HTML, record how many internal notes were stripped, or warn when the count changes unexpectedly between builds. A content migration can clean stored fragments while retaining a metric that helps reviewers estimate how much hidden material was present.

Because the algorithm has no network calls, model inference, randomness, clock access, or document reserialization, identical input always produces identical output. For very large collections, process each document as its own item so errors and counts remain attributable to a specific source.

Prepare HTML for publishing

Strip editorial notes and disabled fragments before markup is sent to a production site.

Sanitize generated build output

Remove generator annotations while preserving all other bytes, spacing, and tag formatting.

Audit hidden source notes

Record the number of removed comments so a build can detect unexpected changes or enforce a zero-comment policy.

Does it reformat or validate the HTML?

No. It preserves every character outside comments and does not parse, repair, indent, or serialize the markup.

What happens if a comment is never closed?

Nothing is removed and you get a message pointing to the position where the unfinished comment began. Treating it as a comment to the end could erase real page content, so add the missing closing marker and try again.

What if a comment contains another opening marker?

It is treated as part of the comment. Each comment ends at the very next closing marker, and everything before it, including tags, line breaks and a second opening marker, is removed with it.

Is a stray closing marker removed too?

No. A closing marker with no opening marker before it is ordinary text and stays where it is. Only complete comments, with both their opening and their closing marker, are removed.

What is the count of removed comments good for?

It lets you check the cleanup. A publishing script can require zero comments in the final page, log how many internal notes were stripped, or warn when the count changes unexpectedly between builds. With no comments, the text comes back unchanged and the count is zero.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/text/remove-html-comments

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/text/remove-html-comments \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text":"<main><!-- draft note --><h1>Hello</h1></main>"}'
{
  "text": "<main><!-- draft note --><h1>Hello</h1></main>"
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "text.remove_html_comments",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

max_chars200000
HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Clean markup without reformatting it

The response includes the cleaned text as its primary value and a comments_removed count for logging, assertions, or reporting.

Understand comment boundaries and errors

The capability therefore rejects the entire request with an invalid_input error that identifies the character position where the unfinished comment began.

Use the count in dependable workflows

Send the HTML in the text field and read text plus comments_removed from the response. Each bounded item costs $0.002 through the API, while the browser version can be used for quick manual cleanup.

What does the capability return?

It returns the cleaned HTML text and comments_removed, the number of complete comment blocks that were stripped.

What happens if a comment is not closed?

The request fails with an invalid_input error identifying where the unterminated HTML comment starts.

What happens when the input has no comments?

The original text is returned unchanged and comments_removed is zero.

How much does an API request cost?

Each request costs $0.002. The same deterministic operation is also available in the browser runner.

Read the full KIT documentation →