HTML Formatter
Format HTML snippets with indentation for easier reading.
Your result will appear here…
How to use HTML Formatter
- Paste an HTML snippet or a whole document.
- Select Format.
- Check inline text and whitespace-sensitive blocks before you use the output.
Example
Input / settings:
<main><h1>Hello</h1><p>Welcome</p></main>
Output:
<main> <h1>Hello</h1> <p>Welcome</p> </main>
An element that contains only text stays on a single line. Formatting the output again returns the same text.
When to use
- Read minified markup copied from a page or a build output.
- Tidy an example before pasting it into documentation.
- See how elements nest while debugging a template.
Overview
HTML Formatter puts each tag on its own line and indents child elements by two spaces. It works on the text of your markup, splitting it into tags, comments and text without building a document tree, so it neither validates nor repairs the HTML. Tag names, attributes and text are left as written; only the whitespace between them changes.
Supported input
HTML text
Output details
formatted HTML
Common mistakes
- Inline elements are split onto separate lines. <p>Hello <b>world</b>!</p> becomes four lines with the ! on its own line. A browser turns that line break into a space, so the page shows world ! instead of world!.
- Elements that depend on exact whitespace are only safe when they hold plain text. <pre> a <b>x</b>\n b</pre> is re-indented and gains extra lines inside the pre element.
- Script contents are read as markup, not as raw text. In <script>if (a < b) { x(); }</script> the < is taken for the start of a tag and the line is split there.
- Broken markup is not reported or repaired. <div><p>Unclosed<div>after</div> is indented as if it were balanced, and the closing tags are still missing.
Practical tips
- Format a copy, then compare it with the original in Text Diff to see exactly which whitespace changed.
- Keep script and style blocks out of the snippet you format when they contain < or > characters.
Privacy and security
This tool runs entirely in your browser. Your input is never uploaded to our servers. Formatting runs locally and only inserts or removes whitespace between tokens. It does not sanitize the markup, and the tool never renders or executes it, so formatted HTML is exactly as untrusted as the input.
References
Frequently asked questions
Does HTML Formatter validate or fix my markup?
No. It splits the text into tags and text and re-indents them, even when tags are missing or misplaced.
Can I change the indentation width?
No. Child elements are indented by two spaces, and this page has no indentation setting.
Does the formatter keep HTML comments?
Yes. A comment is kept on its own line. HTML Minifier is the tool that removes ordinary comments.