Beautify HTML with block-aware indentation, or minify it. The contents of pre, textarea, script and style are preserved.
How to use the HTML Formatter
Paste your HTML into the input box.
Choose Beautify to indent it or Minify to compress it.
Pick the indent size, then copy the result.
This is an HTML formatter that beautifies markup with block and inline aware indentation, or minifies it by collapsing whitespace and stripping comments. You pick the indent size when beautifying.
Beautifying indents elements according to how they nest, so the structure of a document, which elements contain which, becomes obvious. That makes hand-written or generated HTML far easier to read and debug.
Both beautify and minify run entirely in your browser, so your markup never leaves your device.
It deliberately leaves the contents of pre, textarea, script and style untouched, because whitespace inside those elements is significant: reformatting them would change preformatted text, what users type, or the meaning of your code.
Minifying removes comments and collapses runs of whitespace, which trims the file size browsers have to download. It is most useful as a build step for production pages.
The minifier keeps a single space between tags rather than removing it entirely, because whitespace between inline elements is actually rendered, and dropping it can shift your layout. This caution avoids the subtle visual bugs aggressive minifiers can cause.
Frequently asked questions
It indents elements based on their nesting and structure, while leaving the contents of pre, textarea, script and style untouched, since whitespace there is significant.
It removes comments and collapses runs of whitespace to a single space. It keeps single spaces between tags rather than removing them, because whitespace between inline elements is rendered and dropping it can shift the layout.
No. Both beautify and minify run entirely in your browser, so your markup never leaves your device.
It is designed not to. By keeping single spaces between inline elements, it avoids the layout shifts that can happen when whitespace between tags is removed too aggressively.
No. It formats and minifies the markup but does not check it against the HTML specification, so it will reformat even if a tag is unclosed or misused.
Embed this tool
Add this tool to your own website. Copy the snippet below; it stays up to date automatically.
<iframe src="https://monu.tools/embed/en/html-formatter" width="100%" height="640" style="border:1px solid #e5e5e5;border-radius:12px;max-width:680px" loading="lazy" title="Monu Tools"></iframe>Related tools
Beautify and prettify JavaScript with consistent indentation and spacing. Runs entirely in your browser.
Convert CSV to an Excel .xlsx file and Excel back to CSV, entirely in your browser. Works in both directions.
Generate TypeScript interfaces from a JSON sample, with nested types, arrays and optional fields. Runs in your browser.
Convert JSON to XML and XML back to JSON, in both directions, entirely in your browser.