HTML Beautifier

Formats minified or inconsistent HTML with two-space indentation. Keeps inline elements on the same line as their text and formats embedded script, style and JSON-LD blocks.

The output will appear here.
Advertisement Kelivo — a word game by icyabmod, on Google Play and the App Store

How HTML Beautifier works

Formats minified or inconsistent HTML with two-space indentation. Keeps inline elements on the same line as their text and formats embedded script, style and JSON-LD blocks.

Input HTML
Output Readable HTML
Works done 2,507

How to use it

This HTML beautifier turns minified or inconsistently indented markup into a clean tree with two spaces per level. Block elements start on their own line, while inline elements such as links, strong and span stay inside the sentence they belong to, so the formatting never changes what the page looks like. Embedded <script> and <style> blocks are formatted too, entirely in your browser.

How to use the HTML beautifier

  1. Paste the HTML you want to read: a full page, an email template or a single component.
  2. Format it with the "Run tool" button; the Ctrl + Enter shortcut works as well.
  3. Scan the indentation to understand the structure and spot misplaced closing tags.
  4. Copy the result back into your editor or download it as a text file.

Formatting rules at a glance

ContentHow it is laid out
Block elements such as div, ul, section, tableOwn line, children indented one level
Inline elements such as a, em, imgKept on the same line as surrounding text
A block holding only text and inline elements, up to 100 charactersStays on one line, for example <li><a href="/">Home</a></li>
Longer text blocksSplit into opening tag, text and closing tag
script and styleFormatted as JavaScript and CSS at the right depth
JSON-LD structured dataPretty-printed JSON
pre and textareaPreserved exactly
Comments and the doctypeKept, each on its own line

Whitespace inside tags is tidied as well, so <div class = "card"> becomes <div class="card">, while quoted attribute values are left alone.

A worked example with optional end tags

HTML allows some closing tags to be omitted, and generated markup often does exactly that. Consider <div class="card"><h2>Pricing</h2><p>From <strong>$9</strong> per month</p><ul><li>One site<li>Email support</ul></div>. The beautifier puts <h2>Pricing</h2> and the whole paragraph on single lines at the second level, with <strong>$9</strong> still inside the sentence. The list opens on its own line, and because a new li implicitly closes the previous one, both items sit at the same depth instead of drifting further right. The same rule applies to p, td, tr, option, dt and dd.

Finding structural bugs through indentation

The beautifier never inserts missing tags, but it exposes them. Format <main><article><h2>Title</h2><div class="body"><p>Text</article></main> and </article> follows the word "Text" directly, stepping back three levels at once with no </p> or </div> line in between. That gap is the signature of an unclosed element, here the div. A useful rule of thumb: when the indentation drops by more than one level in a single step, and the skipped elements are not ones with optional end tags such as li, p or td, a tag above was never closed.

Formatting also makes template reviews easier. Beautify two versions of a page with the same rules and paste them into the text diff checker; differences in indentation disappear and only real changes remain.

Where messy HTML comes from

  • Minified production pages copied from the browser's page source.
  • Email templates built from nested tables, where one stray cell breaks the layout.
  • Output from visual editors and page builders with erratic indentation.
  • Embed codes for maps, video players or forms pasted from third-party services.
  • HTML fragments returned inside JSON fields by an API or headless CMS.

What it will not do

It does not validate markup, add missing end tags, fix incorrect nesting, wrap long lines at a fixed width, reorder attributes or change tag case. Indentation is always two spaces. Those limits are deliberate: every change it makes is one that browsers ignore, so the formatted page renders exactly like the original.

Privacy and related tools

Formatting runs in JavaScript in your browser; the markup is not sent to the server, and the page only increments an anonymous usage counter. When you are ready to ship, the HTML minifier reverses the process. Separate stylesheets and scripts can go through the CSS beautifier and the JavaScript beautifier.

Advertisement Clicker Alchemist — a mobile game by icyabmod, on Google Play and the App Store

Frequently asked questions

It is designed not to. Inline elements and text stay on the same line, so no new spaces appear between words, and the line breaks and indentation added around block elements are ignored by browsers. Content inside pre and textarea is not touched at all. The only pages that might differ are rare designs that deliberately rely on source whitespace between inline-block elements, which are fragile anyway.

No. It indents what you give it and never adds or removes tags. What it does well is reveal problems: an unclosed div or tags closed in the wrong order make the indentation jump unexpectedly to the left. Look at the lines just above the jump to find the culprit. If you need formal validation, run the formatted output through an HTML validator as a separate step.

A block that contains only text and inline elements and is no longer than 100 characters stays on one line, because splitting it would make short structures like menu items or headings harder to scan. Blocks that contain other block elements, or that run longer than that, are broken into an opening line, an indented content line and a closing line.

Yes. The page you paste is treated as text: nothing is executed, rendered or uploaded. Script blocks are formatted as JavaScript and style blocks as CSS; if one cannot be parsed, for example a client-side template, it is simply re-indented without changes to its content. The formatting happens in your own browser tab and the input is discarded when you clear the field or close the page.