Remove HTML Comments
HTML comments are useful during development, but in production they add noise and can leak implementation details. This tool removes comment blocks (<!-- ... -->) across your document, leaving only the content that actually renders. 🧹
🚀After stripping comments, you may also remove excess tag attributes or delete empty tags to further reduce page weight.
What gets removed?
- HTML comments in the form
<!-- any content --> - Multi-line comment blocks created during development
- Notes, TODOs, and disabled markup left in the source
- Framework-generated comments that don't affect rendering
Why remove comments?
- Cleaner source: easier to read and maintain.
- Smaller payload: fewer bytes sent over the network.
- Security: avoids leaking internal notes or hints.
- Better exports: comments don't pollute DOCX or text conversions.
Example: Before and After
Before (with comments):
<!-- Cleaned by Pretty HTML -->
<div class="card">
<p>Content</p>
</div>
After (cleaned):
<div class="card">
<p>Content</p>
</div>
How to use this page
- Paste or drop your HTML into the editor.
- Check the Comments button.
- Click Pretty to remove comment nodes.
- Download the cleaned HTML or DOCX if needed.
Common places comments appear
During development
- Temporarily disabled markup
- Notes explaining layout hacks
- Debug reminders and TODOs
Generated content
- CMS or page-builder markers
- Framework hydration hints
- Export artifacts from editors
Impact on performance and SEO
Comments do not affect how browsers render a page, and search engines generally ignore them. However, they still increase file size and can reveal information you'd rather keep private. Removing comments won't change semantics or rankings, but it contributes to a cleaner, faster, more professional output, especially when combined with other cleanup options. 📉
| Aspect | With comments | Without comments | Result |
|---|---|---|---|
| Source readability | Noisy, mixed signals | Focused on content | Easier maintenance |
| Page size | Larger | Smaller | Faster transfers |
| Security | Possible info leaks | No internal notes | Safer output |
| Exports | Comments included | Clean content | Better conversions |
Removing comments with JavaScript
To remove comments programmatically, traverse the DOM and delete nodes with nodeType === Node.COMMENT_NODE. This approach is robust and avoids the pitfalls of regular-expression-based stripping. ⚙️
function removeHtmlComments(html) {
var parser = new DOMParser();
var doc = parser.parseFromString(html, 'text/html');
var walker = doc.createTreeWalker(
doc.body,
NodeFilter.SHOW_COMMENT,
null,
false
);
var toRemove = [];
for (var n = walker.nextNode(); n; n = walker.nextNode()) {
toRemove.push(n);
}
toRemove.forEach(function (c) {
c.parentNode.removeChild(c);
});
return doc.body.innerHTML;
}
Optional: combine with other cleaning options
Removing comments often reveals empty elements or unused attributes.
Running a follow-up cleanup step keeps the final markup tidy and consistent. ✅
FAQ
Will this remove conditional comments?
Modern browsers no longer rely on legacy conditional comments. If you still target very old environments, review the output before deploying.
<!--[if lte IE 8]>
<link href="IE8fonts.css" rel="stylesheet" type="text/css">
<![endif]-->
Does this help SEO?
Indirectly with faster loading time id does. While comments aren't indexed, cleaner markup and smaller pages contribute to better performance and maintainability.

Can comments affect layout?
Not directly, but they can confuse editors and tools that process the DOM. Removing them simplifies downstream processing.
Is it safe to remove all comments?
For production output, yes. Keep commented source versions in your repository if you need explanations later.





