HTML Formatter

Paste messy or minified HTML and get clean, indented markup back — one element per line, nested tags lined up, void elements handled. Code inside script, style and pre blocks is left exactly as it is.

Runs in your browser — your code and data never leave this device

How do I format HTML online for free?

Paste your HTML here: this free online HTML formatter adds clean indentation, one element per line, so nested markup is easy to read — with 2 or 4 spaces of indent, your choice. Script, style, pre and textarea blocks are copied through unchanged, and nothing is uploaded: the formatting runs in your browser.

Size: 0 B → 0 B
Input characters: 0

Related tools

How to use the HTML Formatter

  1. Paste your HTML into the Input box on the left, or click Sample to load a minified example page.
  2. Choose 2 or 4 spaces for indentation, then click Format HTML. Nested tags are indented to match their depth.
  3. Script, style, pre and textarea blocks are copied through unchanged, so code inside them is never reflowed.
  4. Click Copy output or Download to save the formatted markup, and check the result in a browser before publishing.

For the full picture — how indentation reveals unclosed tags — read our guide: How to Format HTML.

What the formatter does

A formatter takes markup that a machine produced — one long line, or indentation that drifted over years of edits — and lays it out so a human can read it. Each element goes on its own line, nested elements are indented one step deeper than their parent, and the structure of the page becomes visible at a glance. Void elements like img, br and input, which never have a closing tag, are recognised and do not increase the depth.

Comments and the doctype are kept at the depth where they appear. Text between tags is trimmed and placed on its own line. The result is not a prettier version of the same page for visitors — browsers do not care about indentation — it is a prettier version for the next person who has to read the code, which is usually you, six months later.

Why format HTML at all?

The most common reason is inherited code: a page built by a visual editor, exported from a CMS, or minified by a build step arrives as a wall of text, and something in it needs fixing. Formatting turns a thousand-character line into a structure you can scan, so the unclosed div or the duplicated id stops hiding. Code review is the same story — a formatted diff shows what changed, while a minified diff shows everything changed.

It also helps when you are learning. Seeing the nesting laid out makes the box model, the document outline and the parent-child relationships concrete in a way a single line never does. And when two people edit the same file, a consistent format keeps the version-control history readable instead of full of whitespace noise.

The honest limits

This formatter works on well-formed HTML. Badly broken markup — a missing closing tag, a tag closed in the wrong order — will still be indented, but the indentation follows the tags as written, so the result can look odd. That is often useful in itself: a section indented one level too deep is a clue that a tag was never closed.

Two things to check before you publish formatted markup. First, formatting puts a line break between tags, and browsers read a line break between inline elements as a space — so <b>x</b><i>y</i> on separate lines gains a space that was not there. For block layout this never matters; for tight inline content, check the result. Second, the content of script, style and pre blocks is copied through untouched, which is deliberate — reflowing code would risk breaking it.

Clean indentation, untouched code blocks: what formatting does

To format HTML code online free, paste it and the formatter indents every element by its depth in the document: children sit one step in from their parents, so the structure is visible at a glance. Void elements such as img, br, input and meta do not add depth, because they have no closing tag and no children — so the indentation always matches the real structure of the page.

What it leaves alone matters as much as what it changes: the contents of script, style, pre and textarea blocks are copied through exactly as they are, because re-indenting code or preformatted text would change its meaning. One honest limit: this is a beautifier, not a repair tool — it does not fix broken HTML, though a missing closing tag usually shows up as indentation that suddenly runs too deep, which is a useful clue when you are hunting for it.

Frequently asked questions

Does formatting change how my page looks?

For block layout, no. But a line break between two inline elements renders as a space, so formatting can add a small gap inside tight inline content such as icon and label pairs. Check the result in a browser before publishing.

What happens to script and style blocks?

They are copied through unchanged, along with pre and textarea blocks. Their contents are never reflowed, because changing whitespace inside code can break it.

Can it fix broken HTML?

No. It indents the tags as written, so a missing closing tag shows up as a section indented one level too deep. That makes the problem easier to spot, but you still have to fix the markup yourself.

Why are some elements not indented further?

Void elements such as img, br, input and meta never have children, so they do not increase the depth. Comments and the doctype stay at the depth where they appear.

Is my HTML uploaded anywhere?

No. This tool runs entirely in your browser using JavaScript. Your code is never uploaded, stored or sent anywhere — everything stays on this device.

Can I beautify minified HTML here?

Yes — paste the minified HTML and the formatter spreads it out with clean indentation, one element per line, so you can read and edit it again. The formatting changes only whitespace, so the page looks and behaves exactly as it did.

What indent size should I use — 2 or 4 spaces?

Either works: 2 spaces keeps deeply nested markup compact, while 4 spaces makes the structure easier to scan. Pick the one your project already uses, so the formatted code matches the rest of your files.

What is the difference between formatting and minifying HTML?

Formatting adds indentation so code is easy to read; minifying strips whitespace so the file is as small as possible for production. They are opposites: format when you want to read or edit code, minify when you want to ship it.