HTML Formatter — Beautify and Indent HTML Online
Paste HTML and get one tag per line, indented with 2 spaces, 4 spaces or a tab. Switch to Minify to strip comments and line breaks again; everything runs in your browser.
Related tools
- CSS Minifier Minify CSS by removing comments and whitespace, or beautify minified CSS again. Safe for string values.
- JavaScript Minifier Minify JavaScript with Terser: removes whitespace, comments and dead code, keeps names readable. Runs in your browser.
- Code Formatter Beautify and format HTML, CSS, JavaScript, XML, SQL code. Beautify or minify with customizable indentation and auto-format as you type.
- SQL Formatter Format SQL queries with one clause per line, upper-case keywords and indented joins, conditions and subqueries.
Features
- Beautify HTML into one tag per line with clean indentation
- Indent with 2 spaces, 4 spaces or tabs
- Void elements and self-closing SVG tags never shift the indentation
- Minify mode removes comments and line breaks again
- Copy the result or download it as an .html file
- Runs in your browser; the result is shown as plain text, nothing is uploaded
When You Need an HTML Formatter
HTML from build tools, CMS editors, email builders or a page’s source view often arrives as one endless line. An HTML formatter (or HTML beautifier) puts each tag on its own line and indents every nesting level, so you see at a glance which element sits inside which, spot a missing closing tag and can copy a single block cleanly.
The way back is one click away: Minify strips comments and line breaks again, for example before you paste a snippet into a template. Everything happens in your browser; the markup is never uploaded.
How the Formatter Treats Your Markup
- Line breaks: a new line starts wherever one tag ends and the next begins. Text written together with inline tags stays on one line, so
<p>Hello <strong>world</strong>!</p>is left as it is. - Elements with only text, such as
<li>One</li>or a custom element like<my-badge>New</my-badge>, stay on a single line and do not open a new level. - Void elements (
br,img,input,meta,link,hrand the other void elements) and tags closed with/>, like SVG’s<path/>,<circle/>, never increase the indentation. - Comments and the DOCTYPE keep their own line.
- Indentation: 4 spaces by default, or 2 spaces or a tab.
- Nothing else changes: tag names keep their case, attributes keep their order and quotes, and the content of
<script>and<style>is not reformatted. For that, switch the format to CSS or JavaScript.
Example: Beautify and Minify a Form
Input on a single line:
<form><!-- search --><label for="q">Search</label><input id="q" name="q"><button>Go</button></form>Result with 2 spaces of indentation:
<form>
<!-- search -->
<label for="q">Search</label>
<input id="q" name="q">
<button>Go</button>
</form>Minified again, the comment and all line breaks are gone:
<form><label for="q">Search</label><input id="q" name="q"><button>Go</button></form> Pitfalls and Tips
- No protected zones:
<pre>,<textarea>,<script>and<style>are treated like any other element. Beautify moves a<code>inside<pre>onto its own indented line, which changes what the browser shows. Minify collapses every run of whitespace into one space, inside<pre>and<textarea>too, and a//comment in an inline script then swallows the code after it. Keep scripts in external files or minify them in JavaScript mode. - Spaces between inline elements: minify deletes whitespace between two tags, so
<strong>Hi</strong> <em>there</em>becomes<strong>Hi</strong><em>there</em>and the words run together. Beautify does the reverse:<span>a</span><span>b</span>lands on two lines, and the browser then shows a space. - Comments are removed when minifying, conditional comments like
<!--[if IE]>included. - Not a validator: an unclosed tag shifts the indentation of everything after it. If the indentation looks wrong, check the markup with a validator.
- Safe with untrusted HTML: the result appears as plain text in a read-only field. The markup is never rendered, and scripts in it never run.
Useful Resources