HTML Formatter and Beautifier

Paste HTML and get a consistently indented version — in your browser, with nothing uploaded.

Runs in your browser — nothing you enter is uploaded

HTML Formatter

Press Ctrl+Enter (or Cmd+Enter) to format

Tip: press Ctrl+Enter (Cmd+Enter on Mac) inside a text box to run.

Your result will appear hereFill in the fields and press “Format HTML”.

Formula

  • tokenise → build a tree of tags → print block elements on their own lines, inline content together
  • Void elements (br, img, input…) and raw-text elements (script, style, pre, textarea) are handled specially.

Only the whitespace between tags changes.

Worked example

Minified snippet

HTML
<div><p>Hello <b>world</b>!</p><ul><li>One<li>Two</ul></div>
Indent
2 spaces

Result

Formatted — see below

Lines: 7

Size: 90 bytes

<div>
  <p>Hello <b>world</b>!</p>
  <ul>
    <li>One</li>
    <li>Two</li>
  </ul>
</div>

How it works

Each block-level element goes on its own line, indented by its depth in the tree; inline elements such as <b>, <a> and <span> stay inside their paragraph so text still reads naturally. Attributes are kept exactly as written, including quoted values that contain >.

Whitespace inside <pre> and <textarea>, and the contents of <script> and <style>, is preserved, because changing it could change how the page behaves. Optional closing tags such as </li> and </td> are understood. The formatter points out unclosed or unmatched tags but isn't a validator. For the CSS inside a page use the CSS Formatter; for data use the JSON Formatter.

Assumptions and limits

  • Collapses runs of spaces in normal text to one space, as browsers render them.
  • Input limited to 1 MB.