HTML Formatter
Format and beautify HTML or minify it. Indent size, comment stripping, and self-closing tag awareness.
Enter input above to see the result.
What is this for?
HTML markup arrives in your editor in all sorts of states — minified for production, generated by templating engines with no regard for whitespace, hand-typed and indented inconsistently. This tool reformats any HTML fragment with consistent indentation per nested element, recognising void elements (<img>, <br>, <meta>) and inline elements (<a>, <span>, <strong>) so the output looks like real HTML, not a layout-by-rule. Minify mode strips inter-tag whitespace and optionally comments. Everything stays in your browser.
When to use it
- Pretty-printing a minified HTML email or a "view source" copy of a page so you can read its structure and debug rendering issues.
- Cleaning up a snippet from a CMS, WYSIWYG editor, or generated code before pasting into a code review or PR.
- Minifying a static HTML asset before deploying — reduces file size, removes comments, and improves load times.
- Stripping author comments and debug markup from a template before publishing to production.
- Normalising indentation across a codebase or incoming HTML from third-party sources without installing build tools.
- Converting between self-closing tag notation (
<br/>vs<br>) to match your project's style guide.
How it works
- Paste or type your HTML into the input field. Any size fragment or partial markup is fine.
- Adjust settings: choose indent size (2, 4, or tab), toggle comment stripping, and decide on minify vs. pretty-print mode.
- The tool tokenizes your input into tags, text, and comments, then rebuilds it with proper nesting and whitespace applied.
- View the result instantly in the output pane. Copy it straight to your clipboard — no server upload, all processing happens in your browser.
Common gotchas
- This is a pragmatic tokenizer, not a full HTML5 parser. It works well on real-world fragments but won't recover from severely malformed input the way browsers do. Unclosed tags, mismatched nesting, or entity errors may produce unexpected results.
- Whitespace inside
<pre>,<textarea>,<script>, and<style>is preserved. These elements are treated as raw content and aren't re-indented, which is the correct behaviour. - Inline elements stay on the same line as their parent text.
<p>some <b>bold</b> text</p>won't be split across lines. This avoids unwanted whitespace in rendered output. - "Collapse whitespace" in minify mode changes the rendered output for some content. Multiple spaces become one; if your design or layout relies on specific spacing, leave minification off.
- Minify is not a security boundary. Don't rely on stripping comments to hide secrets — they were already shipped to the client and visible to anyone with browser tools.
Browser and privacy
- This tool runs entirely in your browser using JavaScript. Your HTML never leaves your device, and there are no server logs or analytics.
- Works offline — paste your HTML and format it without an internet connection.