HTML & Markup

HTML Formatter

Paste messy HTML to beautify it with clean indentation or compact it into a single line. Whitespace-sensitive markup such as <pre>, <script> and inline elements is preserved, and your markup never leaves the page.

Runs in your browser v1.0.0

Options

live

HTML input

paste or type

Parsed as text in this tab. Unterminated tags and comments are reported with a line and column instead of failing silently.

Formatted output

live


                

How it works

The input is tokenized in your browser into tags, comments and text, then re-emitted with indentation (Beautify) or with insignificant whitespace removed (Compact). Content inside <pre>, <textarea>, <script> and <style> is copied verbatim so it keeps working, and whitespace between inline elements is kept so rendering does not change. Nothing is uploaded and no network requests are made.

Practical uses

Beautify HTML with configurable indentation or compact it into a single line while preserving whitespace-sensitive and inline markup.

Common ways to use it

  • Re-indent a minified HTML document so it is readable.
  • Compact an HTML fragment into a single line.
  • Keep pre and script content intact while formatting the surrounding markup.
  • Drop comments from compacted output.

Beautify the same fragment at two-space indent

Input

<div><h1>Title</h1><p>Hello <strong>world</strong>!</p><ul><li>One</li><li>Two</li></ul></div>

Output

<div>
  <h1>Title</h1>
  <p>Hello <strong>world</strong>!</p>
  <ul>
    <li>One</li>
    <li>Two</li>
  </ul>
</div>

Verified with the tool's analyze function. The Beautify run reported 14 tags, 7 elements, 6 text nodes and a maximum depth of 3. The paragraph stays on one line because its inline children are kept together.

Options that matter

  • Mode — Beautify adds indentation, Compact removes insignificant whitespace.
  • Indentation — 2 spaces, 4 spaces, or a tab; the control is disabled in Compact mode.
  • Remove comments — drops HTML comments, but only in Compact mode; Beautify still prints comments on their own line.

Things to keep in mind

  • The Remove comments toggle takes effect only in Compact mode. In Beautify mode comments are always emitted even when the box is checked.
  • Whitespace between inline elements is collapsed to a single space, while whitespace around block elements is dropped, so the tool approximates rendering without re-parsing CSS.
  • Text inside elements such as p, h1 to h6, li, td and th is collapsed to single spaces; content inside pre, textarea, script, style and title is copied verbatim.
  • Malformed input such as an unterminated comment or tag produces an empty output with a line and column, while a mismatched closing tag adds a warning but still formats.