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.
Mode
Indent
Preserved as-is
- <script>...</script>
- JavaScript, never reformatted
- <style>...</style>
- CSS, never reformatted
- <pre>...</pre>
- Whitespace kept exact
What does an HTML formatter do?
An HTML formatter takes markup and re-outputs it with consistent, readable indentation — turning a dense, single-line HTML dump into something you can actually scan and edit. This tool parses your HTML using the browser's own built-in HTML parser (the same engine that renders any webpage), so it handles real-world, imperfect HTML the way a browser actually would.
Format vs minify
Format (pretty-print) adds indentation and line breaks so nested elements are easy to read — pick 2 spaces, 4 spaces, or a tab. Minify does the opposite: it strips insignificant whitespace between tags, producing more compact markup — useful before shipping a static HTML file where readability doesn't matter. Either way, the content of <script>, <style>, and <pre> tags is left exactly as written.
Auto-fixing broken HTML
Unlike XML, HTML doesn't require every tag to explicitly close — browsers know that a new <p> or <li> implicitly closes the previous one, and self-closing elements like <br>, <img>, and <input> never need a closing tag. Because this tool uses the browser's real HTML parser rather than a strict XML-style one, pasting slightly malformed markup — a missing closing tag, an unquoted attribute — gets normalized to valid HTML automatically instead of throwing an error.
Working with other formats?
See the XML Formatter for XML, or the JSON Formatter for JSON.