HTML Beautify Formatter
Re-indent tangled or minified HTML into a clean element tree with Prettier.
HTML that has been minified, generated by a template, or copied out of a browser’s view-source arrives as either one endless line or a thicket of inconsistent indentation, and both hide the one thing you usually need to see: the nesting. Which element contains which, where a block actually closes, whether that stray div is inside or outside the section. Beautifying redraws the tree — each block element on its own line, indented by depth — so structure becomes visible at a glance. The sample fragment above, a single line as pasted, comes out as eight lines with the list nested visibly inside the card.
Formatting runs in this browser only, with the Prettier library served from this site — your HTML is never uploaded, stored or put into a link. At the standard width Prettier keeps short markup on one line when it fits (a snippet like <div><p>x</p></div> stays inline); pick the Narrow width if you want every element on its own line.
Quick answers
How do I beautify HTML online?
Paste the markup into a formatter and it re-indents the element tree, one block element per line at its nesting depth. The sample card fragment here goes from one line to eight with Prettier.
Short snippets may stay inline at the standard 80-character width — that is Prettier’s design. This page’s Narrow setting forces one element per line when you want the full tree.
Why does Prettier keep <div><p>x</p></div> on one line?
Because it fits: at the default print width of 80, Prettier treats a 21-character fragment as more readable unbroken. Lower the print width far enough (this page’s Narrow mode uses 10) and it breaks into three indented lines.
Neither output is more correct — they are the same markup. Width is a layout preference, and this tool exposes it instead of hiding it.
How to use
- Paste your HTML into the top box — a minified page fragment, view-source output, a template snippet.
- Leave the line width at 80 for standard Prettier layout, or pick Narrow to put every element on its own line.
- Read the formatted markup below, indented by nesting depth, and copy it back.
- If an element stayed inline, that is Prettier deciding it reads better unbroken at that width — Narrow mode overrides the decision.
About this tool
One Prettier behaviour surprises people and is worth knowing before it surprises you: at the standard width, short markup that fits comfortably stays on one line. The fragment <div><p>x</p></div> is 21 characters, so Prettier returns it inline — that is a deliberate readability choice by the formatter, not a failure. This page therefore offers a Narrow width setting that forces every element onto its own line, which is what you want when the whole point is inspecting structure. Formatting never changes the DOM the browser builds (whitespace-only text nodes aside); it changes only what you can see.
Frequently asked questions
Why did my short HTML stay on one line?
Because Prettier keeps markup inline when it fits within the line width — at 80 characters, a snippet like <div><p>x</p></div> is returned as a single line by design. Choose the Narrow line width on this page and the same snippet comes out as three lines, one element each.
Does formatting HTML change how the page renders?
No element, attribute or word of text is added, removed or reordered. Line breaks and indentation between block elements do not affect rendering; the one theoretical exception is whitespace between inline elements, which browsers already collapse — and Prettier is specifically careful to preserve the rendering of inline content.
Can this format a whole page, or only fragments?
Both. A full document with doctype, head and body formats the same way as a fragment. Very large documents (hundreds of thousands of characters) may take a moment in the browser, since all the work happens on your device.
Is my HTML uploaded anywhere?
No. Prettier runs in this page from files served by this site; your markup is never sent, stored or put into a link. That matters when the HTML is an unreleased page or contains internal URLs — paste freely.
First time embedding? Read the step-by-step guide →
More free tools
UUID Generator
Generate random v4 UUIDs in bulk.
JSON Formatter & Validator
Format, minify and validate JSON in one click.
What Is My IP
See your public IP address instantly. No sign-up, nothing stored.
Regex Tester
Test, check and validate regular expressions with live highlighting.
JWT Decoder
Decode a JWT token without the secret — see its header and payload.
SHA-256 Hash Generator
Generate SHA-256 / SHA-512 hashes instantly.