Clean up your HTML code by stripping out comment blocks while keeping your actual code intact
Our free online tool is built with simplicity and efficiency in mind. Be it an experienced developer cleaning a legacy project or an amateur learning the ropes, you may remove HTML comments from your code in seconds. It’s a simple process, and you have complete control over the outcome.
Keep conditional comments: Check this to keep browser-specific directives such as <!--[if IE]>.Remove empty lines: Check this to tidy up the extra whitespace left after removing comments.As soon as you press the button , this tool will process your input instantaneously . Below you'll see the cleaned code, ready to be copied to your clipboard with a single click, downloaded as a .txt file or cleared to start a new session. The “Show Example” button will show you a demo with some pre-loaded code with different comment types.
HTML comments are non-visible text in your source code, used for developer notes, instructions, or to comment out code temporarily. They are of great value in development but have no role in the end-user's browser and may be safely deleted for production.
The formal definition of an HTML comment is <!-- Comment Text Here --> The browser ignores everything between the opening <!- and the closing ->. But not all notes are only comments. Knowing their types is important to use our tool efficiently.
<!--[if IE 8]>).<!--#include virtual="/header.html" -->).<!-- This is a comment you can see --> <!--[if !IE]> <link href="non-ie.css" rel="stylesheet" > <![endif]-->
<div class="container"><!-- wrapper div --></div><!--[if lt IE 9]><script src="html5shiv.js"></script><![endif]-->Leaving comments in the live files of your website or application might lead to various unanticipated bad repercussions. While they do not cause any problems during development, their existence in production code is typically considered a bad practice for the following reasons:
Note that you should always preserve a commented version in your development repository. This tool is not for cleaning up your documentation; it is for building a production build.
This tool is versatile and caters to a wide spectrum of experts and enthusiasts in the web development community. Here are the most prevalent situations when you really need an HTML comment cleaner:
Beyond that, the tool is great for anyone working on static site generators, email templates, or anything where HTML is finished and needs to be as slim as possible before distribution.
It really shows how effective comment removal can be to see the transformation side by side. Here’s an example of a sample of HTML with all sorts of comments, and the cleaned output created by our program with the “Remove empty lines” option turned on.
| HTML Code With Comments | Cleaned HTML Output |
|---|---|
<!DOCTYPE html> <html> <head> <title>Example Page</title> <!--[if IE]> <link rel="stylesheet" href="ie-fix.css"> <![endif]--> <!-- Main stylesheet --> <link rel="stylesheet" href="style.css"> </head> <body> <header> <!-- TODO: Update logo link --> <img src="logo.png" alt="Logo"> </header> <div class="content"><!-- start content --> <h1>Welcome</h1> <p>This is a paragraph.</p> <!-- <p>This old paragraph is hidden.</p> --> </div><!-- end content --> </body> </html> | <!DOCTYPE html> <html> <head> <title>Example Page</title> <!--[if IE]> <link rel="stylesheet" href="ie-fix.css"> <![endif]--> <link rel="stylesheet" href="style.css"> </head> <body> <header> <img src="logo.png" alt="Logo"> </header> <div class="content"> <h1>Welcome</h1> <p>This is a paragraph.</p> </div> </body> </html> |
Note that the usual comments are eliminated, but the conditional comment for IE is maintained (default option). The "TODO" notice, the commented-out paragraph block, and the empty lines have been removed, making the file more compact and professional.
Definitely. All processing is done in your browser (client-side). Your HTML code is never transferred to our server and never saved anywhere. Once the website is loaded, you can even unplug from the internet, and the tool will still work perfectly fine, thus your proprietary code stays completely private and secure.
Conditional comments were a proprietary feature of Microsoft Internet Explorer (IE) 5 through 9. They let developers offer certain code or stylesheets to certain browsers only. They are mainly obsolete because they are not supported by contemporary IE and its successor, Microsoft Edge. If you have a really old website that still has to support legacy IE, however, you might want to leave those checked. You can safely uncheck this for all modern projects and delete them.
No. The tool has exact parsing logic that only works on text inside valid HTML comment delimiters (<!-- ... -->). It strictly avoids anything that isn’t a comment, including JavaScript code, CSS or even real HTML tags, even if they are sandwiched between comment markers. Your working code is fully untouched.
This particular tool is tailored to HTML comment syntax. CSS uses /* ... */ and JavaScript uses // or /* ... */. Using an HTML comment remover on CSS/JS scripts will not work properly. For those languages, we advocate utilizing specialist CSS minifiers or JS minification tools, as they know the exact syntax and can safely remove comments without disrupting code.
Examples of HTML Comments
<!-- Main menu begins here --><!--
<div class="old-widget">
This widget is temporarily disabled.
-->