Skip to main content

HTML formatter and minifier

Format HTML or remove ordinary comments locally while retaining text whitespace and script content. No page execution or upload is required.

  • Clipboard
  • Export
Automate

Embed this widget

Customize the result, check the live preview, then copy the code.

Preview

Embed code type

Code to copy

Responsive and automatically resized by Bethemesh.

Was this tool useful?

How does this tool work?

Reformat an HTML document or fragment to inspect its structure without opening the code as an active page. The formatter recognizes tags, attributes and text rather than splitting on every angle bracket. A second action conservatively removes ordinary comments. Scripts are not executed, links and images are not fetched, and your page is not uploaded to a remote formatting service.

Formatting parses HTML and applies structured layout with strict whitespace sensitivity. It does not mechanically put every tag on a new line: inserting separation between inline elements can change visible spaces in a browser.

Embedded script and style content is not reformatted by a second JavaScript or CSS transformation. Use the dedicated language formatters for that. Attribute layout and spelling may be normalized, so output is not an exact reproduction of source writing.

Comment removal does not globally compress whitespace. It deletes only ordinary comment spans recognized by the parser. All other characters remain unchanged, including spacing in text, pre blocks and scripts. Comments marked !, directives starting with # and recognized conditional comments are retained.

Conservative handling does not cover every application convention. Frameworks may use apparently ordinary comments as hydration markers. Keep generated output in its build pipeline and check those conventions before deleting comments. Successful layout is not comprehensive validation of accessibility, SEO or behavior.

How to use this tool

  1. Supply raw HTML

    Paste a fragment or import a .html file. Exclude Markdown fences and template code the HTML parser cannot interpret.

  2. Choose the appropriate action

    Format for review or remove ordinary comments. The second action is not complete page minification including scripts and styles.

  3. Check and retrieve markup

    Inspect inline text, attributes and markers before copying or downloading. Source edits hide old output; reset clears both fields.

Use cases

Inspect isolated HTML components

Expose structure to find containers and attributes. The form does not resolve components or expressions specific to Astro, JSX or other template languages.

Share a markup example

Copy a readable excerpt into technical documentation. Elements remain text here; the tool does not generate a screenshot of their rendering.

Remove explanatory comments

Delete ordinary comments from static fragments without collapsing paragraph or preformatted whitespace. No size reduction is expected when no comments are present.

Examples

Retain a short inline fragment

The fragment may remain on one line with a normalized final newline. Formatting does not force breaks that could introduce visible whitespace.

Input

<div><span>x</span></div>

Result

<div><span>x</span></div>

Remove a comment without altering spaces

Only the note comment disappears. The paragraph keeps spaces around b and pre keeps its spacing and line break.

Input

<!-- note --><p>a <b>b</b> c</p><pre> x  y
 z</pre>

Result

<p>a <b>b</b> c</p><pre> x  y
 z</pre>

Tips and best practices

  • Test output on the real page when inline whitespace affects layout.
  • Use XML Formatter for strict XML; HTML and XML have different tag rules.
  • Removing comments neither eliminates unused CSS nor removes dead JavaScript.
  • Keep commented working sources when annotations help maintain the project.

Sources and references

Frequently asked questions

Why do some tags stay on one line?

Separation between inline elements can create visible whitespace. Formatting respects this context instead of putting every tag on a separate line.

Is comment removal complete minification?

No. It intentionally retains all other text, including significant spaces and scripts. Without ordinary comments, output may match input exactly.

Are embedded scripts and styles executed or formatted?

They are not executed, and HTML layout does not apply embedded-language formatting. Use JavaScript and CSS tools to transform those excerpts explicitly.

Can I delete comments from framework-generated pages?

Check framework conventions first. Comments may carry markers used by its runtime. An action suitable for static HTML does not replace the framework’s build process.

Related tools

Tools similar or complementary to this one.

Similar tools

Format JavaScript, TypeScript or JSX for easier reading without executing code. Processing runs locally in your browser.

DevelopmentUse this tool

Format, minify, and validate an XML document directly in your browser.

DevelopmentUse this tool