HTML Formatter

Format or minify HTML — copy and paste the result.

This free online HTML formatter pretty-prints or minifies HTML, with adjustable indentation. Script and style content is preserved exactly — only the surrounding markup is reformatted. Broken or unclosed tags are auto-corrected using your browser's own HTML parser. No signup, runs entirely in your browser.

Examples:

Mode

Indent

Preserved as-is

<script>...</script>
JavaScript, never reformatted
<style>...</style>
CSS, never reformatted
<pre>...</pre>
Whitespace kept exact
HTML Input

Frequently asked questions

Paste your HTML into the input with the mode set to Format. It's parsed with your browser's own HTML parser and re-indented with your chosen spacing (2 spaces, 4 spaces, or a tab).
Switch the mode to Minify. The tool removes insignificant whitespace between tags, keeping the content inside <pre>, <script>, and <style> untouched, and outputs the HTML as compactly as possible.
Yes, automatically. Because the tool parses your HTML with the browser's own lenient HTML parser (the same one that renders any webpage), it corrects common issues like unclosed <p> or <li> tags the same way a browser would when displaying the page.
No. The JavaScript inside <script> and CSS inside <style> are treated as raw text and copied through exactly as written — only the surrounding HTML structure is reformatted, so your code inside those tags is never touched or re-indented.
No. Everything is parsed and formatted locally in your browser. Nothing is uploaded or stored on a server.
' }, { label: 'Void elements', value: '
' }, { label: 'Unclosed tags', value: '

One

Two

  • Item
  • Item 2' }, ], get _result() { const text = this.input; if (!text.trim()) return { value: '' }; const space = this.indent === 'tab' ? '\t' : ' '.repeat(Number(this.indent)); const value = this.mode === 'minify' ? minifyHtml(text) : formatHtml(text, space); return { value }; }, get output() { return this._result.value; }, loadExample(ex) { this.input = ex.value; }, clearInput() { this.input = ''; }, async copyOutput() { const text = this.output; if (!text) return; try { await navigator.clipboard.writeText(text); } catch { const el = document.createElement('textarea'); el.value = text; document.body.appendChild(el); el.select(); document.execCommand('copy'); document.body.removeChild(el); } this.copied = true; setTimeout(() => { this.copied = false; }, 2000); }, })); if (window.Alpine) { register(); } else { document.addEventListener('alpine:init', register); } })();