HTML Formatter

Beautify minified or messy HTML — each tag on its own line, indented by nesting level — right in your browser. A quick regex tidier, not a full parser.

Developer Tools Free No upload Instant

Loading HTML Formatter…

Your browser is preparing the tool. It runs 100% locally.

Quick Answer

Paste minified or untidy HTML and the tool reformats it so each tag sits on its own line, indented two spaces per nesting level, making the structure easy to read. It is a lightweight regex-based tidier — it does not parse the HTML into a DOM — so it is great for a quick read of compact markup but can misindent void elements such as br and img. Everything runs in your browser; nothing is uploaded.

What the HTML Formatter Does

This tool takes HTML that has been collapsed onto one line, or indented inconsistently, and lays it out with one tag per line and a clean two-space indent for each level of nesting. The result is markup you can actually read and follow.

It is the quick way to make sense of a minified template, a copied snippet, or the output of a tool that produced a wall of tags — without opening an editor or installing anything.

How It Works

The tool uses a regular expression to insert a line break wherever one tag ends and the next begins, so every tag lands on its own line. It then walks those lines keeping a running nesting depth: an opening tag increases the depth, a closing tag decreases it, and each line is indented by two spaces per level.

This is pattern-based, not a true parse. The tool never builds a document tree or checks that the HTML is valid — it simply reacts to the shape of the tags. That makes it fast and dependency-free, and it handles ordinary nested markup well, but it can be fooled by the edge cases a real parser would handle.

Processing pipeline

  1. Break between tags. Insert a line break wherever a tag closes and the next one opens, so each tag is on its own line.
  2. Track nesting depth. Keep a counter that rises on an opening tag and falls on a closing tag.
  3. Indent by level. Add two spaces of indentation for every level of current depth.
  4. Join the lines. Reassemble the indented lines into the formatted HTML, ready to copy.

How it reformats

1 · break the markup so each tag is on its own line 2 · opening tag → indent deeper · closing tag → step back out 3 · two spaces of indent per nesting level note: it reacts to tag shape — it does not parse a DOM
Worked example
Before: <ul><li>One</li><li>Two</li></ul> After: <ul> <li>One</li> <li>Two</li> </ul>

Each level adds two spaces. Void elements such as br and img have no closing tag, so when one sits on its own line the depth counter treats it as an opener and over-indents everything after it — a known limitation of the regex approach.

Privacy

Your HTML never leaves your device. It is reformatted in your browser with no network request, so nothing is uploaded to any server.

Because the work is local, you can safely tidy proprietary templates, internal markup or client code without it being stored or sent anywhere.

Nothing persists between sessions — close the tab and the input and output are gone.

Standards & references

  • HTML syntax — The structure of opening, closing and void tags defined by the WHATWG and W3C HTML standards. The tool relies on the angle-bracket shape of tags, not a formal parse of that grammar.
  • Void elements — Elements like br, img, input, hr, meta and link have a start tag only and no closing tag. A depth counter that expects every opener to close will over-indent after a void element.
  • Parser-based formatters — Tools like Prettier parse code into a tree, discard the original whitespace and reprint it, so they cannot break valid markup and give idempotent output. This tool is a lighter regex tidier, not a reprinter.

Accuracy & Limitations

It handles ordinary nested HTML cleanly, but it is a regex tidier, not a parser. It never checks that the markup is valid or that tags are balanced — it just reflows what you give it, so malformed input produces malformed output.

Void elements are the main pitfall. Because br, img, input and similar tags have no closing tag, the depth counter treats one sitting on its own line as an opener and indents the following lines too deeply. Cleaning those up by hand may be needed.

Attributes that contain a closing angle-bracket character — for example inside a quoted value — can confuse the tag-splitting regex, since it keys off that character rather than understanding quotes. A real parser tracks quoting; this tool does not.

It is not guaranteed idempotent. Running it on already-formatted HTML, or on markup with significant whitespace (such as inside a pre or textarea), can shift spacing in ways that change how the page renders. Use it on markup where whitespace is not meaningful.

Real-World Use Cases

Reading minified HTML

Expand a one-line template into readable, indented markup.

Tidying a snippet

Clean up copied HTML before pasting it into your project.

Reviewing structure

See the nesting of a block at a glance.

Teaching and notes

Present markup clearly in documentation or a lesson.

When to use it — and when not to

Good for

  • Quickly reading minified or messy HTML
  • Indenting a snippet for review
  • Seeing the nesting structure
  • A fast, no-install tidy

Not the best choice for

  • Validating or fixing broken HTML
  • Markup with many void elements you need perfect
  • Content where whitespace matters (pre, textarea)
  • A guaranteed, idempotent reformat

For a robust, parser-based reformat that cannot break valid markup, use a tool built on a real HTML parser (such as Prettier or js-beautify) in your editor. To check that HTML is valid, run it through the W3C validator. This tool is for a fast, in-browser read.

Frequently Asked Questions

Does this validate my HTML?
No. It only reflows and indents the markup. It does not check that tags are balanced or valid, so if the input is broken the output will be too. For validation, use the W3C Markup Validator.
Why is the indentation off after a br or img tag?
Those are void elements with no closing tag. The tool counts an opening tag as a level deeper and expects a matching close, so a void element on its own line makes everything after it indent too far. It is a known limit of the regex approach.
Is it a real HTML parser?
No. It uses regular expressions to split between tags and count nesting depth. It never builds a document tree, which is why it is fast but can be tripped up by edge cases a parser would handle.
Will it change how my page renders?
Usually not, but it can if whitespace is significant — for example inside a pre or textarea, where added line breaks and indentation become visible text. Avoid reformatting those regions.
Can it handle attributes with special characters?
Mostly, but an attribute value containing a closing angle-bracket character can confuse the tag splitter, because the tool keys off that character rather than understanding quotes. A parser-based formatter handles this correctly.
Does it minify HTML too?
No, this tool expands and indents. To go the other way and strip whitespace, use a minifier.
Is my HTML uploaded anywhere?
No. It is formatted entirely in your browser. Nothing is sent to a server, so private or proprietary markup stays on your device.
How much indentation does it add?
Two spaces per nesting level. Each level deeper in the structure adds another two spaces to the line.
Can I run it on a whole HTML file?
You can paste the markup in. For very large files a parser-based tool in your editor will be more reliable, especially if the file uses many void elements or significant whitespace.
Why did running it twice change the output?
Because it is not guaranteed idempotent — it reacts to the current spacing rather than rebuilding from a clean tree. A parser-based formatter discards whitespace first, so it gives the same result every time.
Does it work offline?
Yes. Once the page has loaded, the formatting runs locally in your browser with no further network access.
Should I use this or Prettier?
For a quick in-browser read of a snippet, this is handy. For a shared codebase or anything that must be reliable and consistent, a parser-based formatter like Prettier is the better choice.

References

Re-indents with a regex that breaks between tags and counts nesting depth; honest that it does not build a DOM, so void elements and inline content can throw the indentation off.

PopularHot

JSON Formatter

JSON Formatter for developers — instant, offline-style and privacy-safe.

DeveloperOpen Tool
Popular

JSON Validator

JSON Validator for developers — instant, offline-style and privacy-safe.

DeveloperOpen Tool
Popular

Base64 Encoder

Base64 Encoder for developers — instant, offline-style and privacy-safe.

DeveloperOpen Tool
Popular

Hash Generator

Fast, free Hash Generator that runs entirely client-side in your browser.

DeveloperOpen Tool
Popular

UUID Generator

Fast, free UUID Generator that runs entirely client-side in your browser.

DeveloperOpen Tool
Trending

CSS Minifier

Fast, free CSS Minifier that runs entirely client-side in your browser.

DeveloperOpen Tool

Ready to try the HTML Formatter?

It is free, private and runs entirely in your browser — no sign-up, no uploads, no limits.