HTML Formatter

Lay out minified or messy HTML with each tag on its own line, indented by nesting level. It is a 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 suits a quick read of compact markup but can misindent void elements such as br and img. The HTML Formatter runs in your browser and uploads nothing.

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 read and follow.

Use it to read a minified template, a copied snippet or a tool's 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 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 and 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. That is a known limit 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 carries over between visits. 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 the same output on every run. This tool is a lighter regex tidier, not a reprinter.

Accuracy and limits

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 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.

Where people use it

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 it fits, and when it doesn't

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 that must indent correctly
  • 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. Your browser formats it and sends nothing 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 a second run is not guaranteed to match the first. 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. It does not build a DOM, so void elements and inline content can throw the indentation off.

PopularHot

JSON Formatter

Pretty-print messy or minified JSON with 2-space indents.

DeveloperOpen
Popular

JSON Validator

Paste JSON and find out whether it parses.

DeveloperOpen
Popular

Base64 Encoder

Standard Base64 for any text, emoji included.

DeveloperOpen
Popular

Hash Generator

MD5, SHA-1 and the SHA-2 hashes of any text, as you type.

DeveloperOpen
Popular

UUID Generator

Up to 500 random version 4 UUIDs at once.

DeveloperOpen
Trending

CSS Minifier

Strips comments and whitespace to put a stylesheet on one line.

DeveloperOpen

Back to the HTML Formatter

Paste, run and copy. The code stays in your browser and you don't need an account.