HTML Beautifier

One-line minified markup goes in, indented markup comes out. Pick your indent style, watch the nesting depth as you go, and copy the result straight into your editor.

HTML formatting workbench

Indent

Paste HTML

0 linesReady

Formatted result

0 lines0 B
Nesting depthWaiting for markup

Indentation is a reading aid, not a repair

A beautifier moves whitespace around. That is the whole job. Tags stay in the order you wrote them, attributes keep their values, and a missing closing tag stays missing after the reformat. What changes is your ability to see the structure: five nested divs that arrived as one 3,000 character line become five indented lines, and the one with no partner becomes obvious.

This matters when you inherit output from a template engine, a CMS export, or a build step that stripped every newline. Reading that in a diff is hopeless. Format both sides first, then diff.

Whitespace is not always free

Reformatting looks harmless until an inline element shifts. Browsers collapse runs of whitespace into a single space, but they do render that one space, so a newline inserted between two inline elements becomes a visible gap:

BEFORE
<span>A</span><span>B</span>
AFTER
<span>A</span><span>B</span>

The second version renders as "A B" with a space between. Same problem hits inline-block grids, where that phantom space eats about four pixels per gap and breaks a four-column layout onto two rows. The formatter here keeps common inline tags on their parent line for that reason, though a hand-built component with unusual display rules still deserves a visual check after formatting.

Three places where added whitespace changes rendered output, not layout:

  • <pre> blocks print every space and newline exactly as written. Indenting the contents indents the rendered text.
  • <textarea> treats its contents as the default value. A newline after the opening tag turns into leading whitespace in the field.
  • Template placeholders such as Blade, Twig, or Handlebars tags read as plain text to an HTML parser. Line breaks inside a control block survive the reformat, though the indentation the formatter adds rarely matches what the template outputs.

What each setting changes

SettingEffect on the outputPick this when
2 spacesTwo spaces per level of nestingDeep component markup, where four spaces pushes lines off the screen
4 spacesFour spaces per levelFlat pages, or a codebase that already formats PHP and JS at four
TabsOne tab character per levelA repo with an .editorconfig set to tabs, so the diff stays clean
Wrap widthBreaks lines past the limit, splitting attribute lists across linesElements carrying long class strings from a utility framework
Never wrapOne element per line no matter the lengthYou review in a wide editor and want attributes kept together
Indent head and bodyAdds a level inside <html>, <head>, and <body>Rarely. Most style guides leave those three flush at column zero
Embedded JS and CSS startSets the base column for <script> and <style> contents: one level in from the tag, aligned with the tag, or flush leftFlush left when a long script would otherwise sit five levels deep in a narrow editor

Reading the depth meter

The bar strip under the panes counts how many elements sit at each level of nesting, and the line below it traces the path to the deepest one. Depth is the cheapest structural signal you have on a page you did not write.

Under six levels is ordinary. Past ten, you are usually looking at one of three things: a wrapper div added for every state a component has, a grid system nested inside another grid system, or a table layout that predates flexbox. None of the three break the page. All three make every future CSS override a fight, because each level adds descendant selectors that later rules have to outrank.

Beautify, minify, clean, or validate

Four jobs get confused with each other. Formatting adds whitespace for human readers and ships nothing to production. Minifying removes that whitespace again to cut transfer size. Cleaning deletes markup outright, such as the style attributes and empty spans that arrive when someone pastes from a word processor. Validating reports what breaks the spec and changes nothing at all.

The pairing worth knowing: format while you work, minify in the build. Never commit minified HTML to a repo and never serve the indented version. The round trip is lossless for markup, so a file survives both directions without harm.

Where this formatter stops

  • No syntax repair. An unclosed <div> produces indentation that keeps drifting right. That drift is the signal, and fixing the tag is your job.
  • No attribute sorting or rewriting. Quote style, attribute order, and duplicate attributes all pass through as written.
  • Template syntax stays plain text. Blade directives, Twig blocks, and JSX expressions are not parsed as structure, so nesting inside them is not indented the way the rendered output nests.
  • Embedded scripts follow general rules. Contents of <script> and <style> get reformatted, though the line breaks land where a generic formatter puts them, not where Prettier or your linter would. In a repo that enforces a style, format scripts with the JavaScript beautifier or your own toolchain and paste the result back.
  • Large files slow the page. Formatting runs on the main thread, so a file past roughly 1 MB pauses the tab while the pass completes.

Everything runs inside your browser. The markup you paste never leaves the tab, which matters when the page you are debugging contains a customer name, an internal URL, or an API key someone left in a data attribute.

HTML formatting questions

Indent styles, whitespace side effects, template syntax, and what the formatter leaves alone.

How do I beautify HTML online?

Paste your markup into the left pane. Formatting runs after a short pause in typing and the indented result appears on the right. Pick an indent style from the top rail, then copy the output or download it as formatted.html.

Does beautifying HTML change how the page renders?

Almost never, with one exception worth checking. Browsers render collapsed whitespace between inline elements as a single space, so a line break inserted between two spans or inline-block boxes adds a visible gap. Contents of pre and textarea elements are also whitespace sensitive.

Can it fix broken or unclosed tags?

No. The formatter moves whitespace and nothing else. A missing closing tag shows up as indentation that keeps stepping right and never returns, which makes the break easy to spot, but the repair is manual.

Should I use spaces or tabs?

Match the repo. If an .editorconfig or a linter already sets the indent style, follow it so your reformat does not rewrite every line in the diff. With no house rule, two spaces keeps deeply nested component markup readable on a narrow screen.

Does it handle Blade, Twig, or Handlebars templates?

Partly. Template directives pass through as text, so the file stays intact, but the formatter indents by HTML tags alone. A block that opens inside a loop directive gets indentation matching the raw file, not the rendered output.

Is my HTML sent to a server?

No. The formatter runs as JavaScript in your browser. Nothing is uploaded, stored, or logged, and closing the tab discards both panes.