HTML Formatter
Developer Tools
Beautify messy or minified HTML into a clean, indented document with consistent spacing and line breaks.
Runs entirely in your browserAbout HTML Formatter
The HTML Formatter takes any HTML — a one-line server response, a copy-paste from an email template, or a snippet from your DOM inspector — and returns it cleanly indented and ready to read. It uses `js-beautify`, the same engine behind many editor and IDE formatters, so the output matches what your team's tools would produce.
You can choose between 2 spaces, 4 spaces, or a tab character for indentation. Newlines are preserved but capped, void elements (`<br>`, `<img>`, etc.) are handled correctly, and inline-element wrapping is gentle so paragraphs stay readable. The tool runs entirely in your browser — useful when the HTML you're formatting contains internal URLs, customer data, or unreleased copy.
How to use
- 1
Paste your HTML
Drop your HTML into the left editor. Output formats live as you type.
- 2
Pick an indent style
Use the Indent dropdown to choose 2 spaces, 4 spaces, or Tab.
- 3
Copy or download the formatted output
Use the Copy button to send the formatted HTML to your clipboard, or Download to save as a .html file.
Examples
Cleaning a minified template
Server-rendered HTML often arrives on a single line. The formatter splits it into a readable tree.
Input
<!doctype html><html><head><title>Hi</title></head><body><main><h1>Hello</h1><p>Some <strong>messy</strong> HTML.</p></main></body></html>Output
<!doctype html>
<html>
<head>
<title>Hi</title>
</head>
<body>
<main>
<h1>Hello</h1>
<p>Some <strong>messy</strong> HTML.</p>
</main>
</body>
</html>Frequently asked questions
Does it preserve my comments and DOCTYPE?+
Yes. HTML comments and the DOCTYPE declaration are left intact; they just get appropriately indented.
Will it modify my HTML semantically?+
No — only whitespace changes. The DOM produced by the formatted output is identical to the input.
Can it format HTML with embedded `<script>` or `<style>` blocks?+
Yes. Embedded JavaScript and CSS are detected and indented along with the surrounding HTML.
Why is my output wrapped strangely?+
The formatter wraps lines around 120 characters by default to keep diffs readable. Very long attribute lists may break across lines.
Does the tool send my HTML anywhere?+
No. `js-beautify` runs in your browser; no network calls are made during formatting.
Related tools
JSON Formatter
Format, beautify, and explore JSON with an expandable tree view. Includes indent control and minify.
JSON Validator
Validate JSON structure and pinpoint syntax errors by line and column.
CSS Formatter
Format and organize CSS automatically with configurable brace and indent styles.
SQL Formatter
Beautify SQL queries with proper indentation across Postgres, MySQL, SQLite, and MSSQL dialects.
XML Formatter
Format XML into a clean, readable structure with attribute control.
JSON to XML Converter
Convert JSON data into well-formed XML quickly.