HTML Formatter
Beautify, indent and pretty print your HTML code
Input
Output
Paste your input on the left and the result shows up here.
Or drop a file on this box, , or .
What Is an HTML Formatter?
An HTML formatter takes messy, minified, or poorly indented HTML (HyperText Markup Language) and transforms it into clean, properly indented code. Whether you're working with a single snippet or an entire page, the formatter adds consistent indentation, aligns opening and closing tags, and makes the document structure immediately visible.
Well-formatted HTML is easier to read, debug, and maintain. The WHATWG HTML Living Standard defines the language's syntax, and our formatter respects those conventions: proper nesting of elements, handling of void elements like <br>, <img>, and <input>, and preservation of content inside <pre>, <script>, and <style> blocks.
One honest caveat. The formatter puts every tag and every run of text on its own line with a two-space indent, inline tags like <span> and <a> included. That is what you want for reading a template or finding the unclosed <div>, but the new line breaks can add a visible space between inline elements, so keep the original for production or run it through a minifier.
How to Use the HTML Formatter
Formatting reruns as you edit, so these three steps are mostly about what to do with the indented result.
Paste, Upload, or Load Sample
Drop your HTML into the Input panel on the left. If it is sitting on disk, Upload takes .html, .htm and .txt files. Click Sample to see example messy HTML.
<div class="wrapper"><h1>Hello</h1><p>World</p><ul><li>Item 1</li><li>Item 2</li></ul></div> The formatter handles any HTML: full documents with doctype, partial snippets, or even single elements.
View Formatted Output
The right Output panel shows the beautified HTML a moment after you stop typing. Nested elements get 2-space indentation, and the tag hierarchy becomes clear at a glance. You can validate the result with the W3C Markup Validator.
Copy, Download, or Minify
Copy takes the indented markup and Download saves it as formatted.html. Minify squeezes the Output pane back into compact HTML once you have finished reading it, and Clear on the Input pane makes room for the next document.
When You'd Actually Use This
Cleaning Up Minified HTML
Production HTML is often minified for performance. When you need to inspect or edit it, this formatter restores proper indentation so you can understand the structure. Works great with output from build tools like minification pipelines.
Formatting Email Templates
Email HTML is notoriously messy with deeply nested tables and inline styles. Formatting makes it manageable so you can debug rendering issues across email clients.
Tidying CMS Output
Content management systems often generate bloated, poorly formatted HTML. Run it through the formatter to clean it up before editing or migrating content.
Standardizing Team Code
When multiple developers contribute HTML, formatting styles vary. Use this tool to enforce consistent indentation and structure across your project before code review.
Common Questions
Does the formatter change my HTML structure?
No. The formatter only adjusts whitespace and indentation. It does not add, remove, or reorder any HTML elements, attributes, or content. Your markup stays structurally identical.
How are void elements handled?
Void elements like <br>, <hr>, <img>, <input>, <meta>, and <link> are recognized as self-closing and placed on their own line without an indented child block. See the MDN void element reference.
Is my HTML data stored anywhere?
No. The formatter is a small tokenizer in this page's script, so your markup is never uploaded. That also means it keeps working if you go offline after the page loads.
What indentation does it use?
The formatter uses 2 spaces per indentation level, which is the most common convention for HTML. This keeps nested structures readable without consuming too much horizontal space.
Does it preserve content inside script and style tags?
Yes. Whatever sits between the opening and closing tags of <textarea>, <pre>, <style> or <script> is copied across untouched. Re-indenting there would change the text a visitor sees in a code sample or form field, or alter the contents of a template literal inside a script.
Can I format partial HTML snippets?
Absolutely. You don't need a full HTML document with <!DOCTYPE> and <html> tags. The formatter works with any HTML fragment, whether that is a single <div>, a table, a list, or a complete page.
Related HTML & Formatting Tools
Formatting is just one part of working with HTML. Here are other tools that pair well with it: