ToolsHub4u

Indent minified or messy HTML

Paste compact HTML and get one block element per line with indented children. Script, style, pre and textarea content is copied without changes.

  • Preserves raw blocks
  • Indent size option
  • Runs locally
Ready Developer & Utility
1Enter
2Adjust
3Copy result

HTML Beautifier

1

HTML input

No data yet Live
2

Beautified HTML

Indented 17 lines from 245 characters.

Beautified HTML

  • Raw blocks were preservedScript, style, pre and textarea content is copied without re-indenting, because whitespace inside those elements can change behaviour.
  • Inline elements stay on the text lineLinks, spans, strong text and similar inline tags are kept with their surrounding words rather than forced onto separate lines.
Input lines
1
Output lines
17
Characters
325

This is a whitespace formatter, not an HTML parser. It does not repair invalid nesting, close missing tags, normalise attributes or validate the document.

This page puts one tag per line and indents nested elements, turning a compressed HTML string into something you can read. Paste the markup, choose two spaces, four spaces or a tab, and the formatted version appears beside the form. It works on text, so it does not need a server or an account.

The formatting is structural, with a light repair pass. The page closes elements that were left open, drops a closing tag that has no matching element, and reports how many repairs it made. It is still not a validator: it does not check attribute rules, duplicate ids or whether the document is valid against the HTML specification.

What changes in the output

Block-level elements start on a new line, and their children are indented one level deeper. The closing tag returns to the parent's level. Inline elements such as a, span, strong and em stay with the words around them, so a sentence containing a link is not broken across four lines.

The doctype stays at the top and is not indented. The html, head and body elements nest in the usual order. Comments are treated as text and keep their position. The output adds line breaks, so the character count almost always rises even when the input was valid; the stats show both the input and output size.

Attributes are left exactly as written. The formatter does not reorder them, quote an unquoted value or fold a multi-line tag onto one line. If an attribute value contains >, the tokeniser still has to find the end of the tag, so unusual markup is worth checking by eye.

Indentation, wrapping and the raw blocks

Two spaces is a good default for HTML because deep nesting is common. Four spaces makes each level easier to see but pushes content far right in a table-heavy document. A tab is compact, though its width depends on the editor, so a mixed team should agree on one setting.

Wrap long text nodes now works. With it on, any output line longer than 100 characters is broken between words, and the continuation keeps the same indentation. It never splits inside a word, so a long URL or an unbroken token stays on one line. With it off, each run of text stays on a single line, which is the better choice when you want a diff to show one logical change per line.

script, style, pre and textarea are copied without re-indenting, because whitespace inside them can change behaviour. That is the correct decision for code samples and inline scripts, and the line count now counts the physical lines inside those blocks rather than treating the whole block as one. A pre with three lines therefore adds three to the output count, not one.

A worked example

A 31-character snippet with two paragraphs was pasted with two-space indentation. The result was four lines and 38 characters, with each paragraph on its own line.

Formatting results for four inputs
InputSettingResult
<div><p>one</p><p>two</p></div>2 spaces4 lines, 38 characters, no repairs
Unclosed div and stray p, 40 characters2 spaces6 lines, 53 characters, 2 repairs
pre with three physical lines, 37 characters2 spaces6 lines, 44 characters
206-character paragraphWrap off / on1 line / 3 lines

The malformed run is the important one. The input was <div><p>open<span>no close</div></p><br>. The pending p is now closed before the div, the stray </p> is dropped, and the stats report two repairs. The output nests correctly instead of putting a closing div above a pending paragraph.

The wrap run shows the new control doing its job. With the option off, the whole paragraph is one 206-character line. With it on, the same text becomes three lines, and no word is broken. The output length is unchanged because wrapping adds only line breaks, not characters.

Repair is not validationThe page closes what is open, but it cannot know whether the tag belonged there. Review any input that reported repairs, and run a validator if the document will be published.

Raw blocks and inline tags

The raw-block rule protects four elements. A style block keeps its CSS on the lines you wrote; a script keeps its JavaScript; a pre keeps its spaces and newlines; a textarea keeps its default value. Re-indenting any of them would change what the browser sees, so the formatter copies the content between the opening and closing tags as one unit.

Inline elements are kept on the text line for a similar reason. Splitting <p>Formatting runs <strong>in your browser</strong>.</p> across several lines would add whitespace inside the sentence and could change how the text wraps. The formatter therefore keeps the paragraph on one line and only breaks at block boundaries, or at the wrap width when wrapping is on.

When to use it, and what to use next

Use this page when you have a template, an email or a copied snippet on one line and you need to see its structure. It is also useful before a review, because a formatted file makes a diff readable, and the repair pass gives a broken fragment a usable shape. It is less useful as a build step: it does not minify, and its output is larger than the input by design.

For the opposite direction, the HTML minifier removes comments and optional whitespace. For CSS inside a style block, paste the CSS itself into the CSS beautifier, because this page treats the block as raw text. To convert the markup rather than format it, the HTML to Markdown converter is the relevant tool.

Questions

Common questions

Short answers about this tool and its limits.

Does it fix unclosed tags?

Yes, in nesting order. Elements still open at the end, or left open when a parent closes, are closed for you. A closing tag with no matching open element is dropped. The stats report how many repairs were made.

What does the wrap checkbox do now?

It breaks output lines longer than 100 characters between words, keeping the indentation on continuation lines. It never splits a word, so a long URL stays intact. With it off, each text run stays on one line.

Does a pre block count as one line?

No. The line count includes the physical lines inside a pre, textarea, script or style block, even though the block itself is copied without re-indenting.

Are inline tags put on their own lines?

No. Links, spans, strong and em stay with the surrounding words so the sentence does not gain whitespace. Only block-level elements start a new line.

Does it format the CSS inside a style tag?

No. The style block is preserved as raw text. Paste the CSS into the CSS beautifier if you want it formatted, then put it back.

Can I choose tabs instead of spaces?

Yes. The indent control has a tab option. Tabs render at different widths in different editors, so agree on the setting with anyone who shares the file.

Is a repaired document valid HTML?

Not necessarily. The repair pass fixes open and stray tags, but it does not check attribute rules, duplicate ids or element placement. Run a validator if the document will be published.

Is my HTML uploaded?

No. Formatting runs in the browser, with no account and no server copy. The result disappears when you close the tab unless you copy or download it.