100% local — your data never leaves your browser

HTML Formatter — Read a Page’s Source

Reindent HTML. Inline elements keep their line, because a line break between them is a space on the page — the source reads, the page stays put.

Instant Private Zero cookies
Indentation

HTML input

HTML output

What this tool does

Minified or badly indented HTML becomes readable HTML.

<ul><li>a</li><li>b</li></ul>
<ul>
  <li>a</li>
  <li>b</li>
</ul>

One indentation level per nesting level, two spaces by default and four if you prefer. Tag names, attributes and their order are untouched: this is a layout pass, not a rewrite.

A line break is not free

<p>Hello <b>world</b> again</p>

That stays on one line. In HTML, whitespace between inline elements is part of the text: break the line between </b> and again and you have added a space — visible in the rendering, in a selection, in a copy-paste. The formatter therefore indents around block elements (div, p, ul, table…) and leaves runs of inline content alone, however long they get.

It is the same rule the HTML minifier applies in the other direction, and for the same reason: nothing that changes the rendered page counts as formatting.

What it never touches

  • <pre> and <textarea>. Their whitespace is displayed exactly as written — reindenting them would rewrite the page and the form value.
  • <script> and <style>. Their content is JavaScript and CSS, not HTML; the JavaScript and CSS formatters on this site are the tools for those.
  • Your attributes. Names, values, quotes and order come out as they went in, spaces inside a value included.

It is not a validator

<div><p>x</div>
<div>
  <p>x
</div>

The unclosed <p> comes back unclosed. A formatter reads the document you give it and lays it out; guessing where a tag was meant to close would be rewriting your markup on a hunch. To know whether a document is well-formed, use a validator — the W3C one, or your browser’s dev tools, which show you the tree the parser actually built.

Private by design

Everything runs locally in your browser with JavaScript. Your data is never uploaded, which makes the tool safe for sensitive content, and it keeps working offline.

Frequently asked questions

Why are some tags left on the same line?
Because separating them would change the page. `<span>a</span><span>b</span>` renders as “ab”; put a line break between the two and the browser renders “a b”. Whitespace between inline elements is content, so the formatter indents around block elements and leaves inline runs alone. The HTML minifier on this site keeps the same rule in reverse.
Is my `<pre>` block reindented?
No. Inside `<pre>`, every space and every newline is displayed as written, so touching them would rewrite what your visitors see. The same goes for `<textarea>`, whose content is the field’s value, and for `<script>` and `<style>`, whose content is not HTML at all.
Does it fix broken HTML?
No — it is a formatter, not a validator and not a repair tool. `<div><p>x</div>` comes back indented with the `<p>` still unclosed: the tool lays out what it reads rather than guessing at what you meant. A tidy result says nothing about whether the document parses the way you expect.

Related converters