Code Tools

HTML Formatter

All tools

Turn one-line or badly nested HTML into readable, indented markup while you type.

How it works

Four simple steps

1

Paste or drop HTML

Type, paste, or drop an .html file onto the input panel.

2

Watch it indent

Every tag lands on its own line with two spaces per nesting level.

3

Minify if needed

Press Minify to strip comments and whitespace between tags instead.

4

Copy or save

Copy the output or download it as formatted.html.

HTML Formatter

About HTML Formatter

You open a template export or a page source from a CMS and the whole document sits on one line. Before you can find the broken div or the stray inline style, you need structure you can scan. The HTML Formatter puts every tag on its own line and indents children by two spaces.

Paste markup or drop an .html file onto the input and the output updates on every keystroke. Each opening tag increases the indent, closing tags step back out, and void elements such as img, br, input and meta stay at the same level. Comments, the doctype and CDATA sections are kept. The Minify button does the reverse, stripping comments and the whitespace between tags, and Download saves the result as formatted.html.

One thing to watch: this is a token-based indenter, not a browser parser. Text inside script, style and pre blocks has its whitespace collapsed to single spaces, so an inline script with // comments can break after formatting. Format the surrounding markup and paste long scripts back in afterwards, or check the structure first with the HTML tag balance checker. When you are ready to ship, shrink the markup for production. More markup utilities live in the code tools collection.

The markup is reformatted by a small JavaScript routine running in the page, so templates containing internal URLs or customer data are never transmitted.

Keyboard shortcut

Ctrl Enter - Run tool
FAQ

Frequently asked questions

See all FAQs

Answers for this tool. For site-wide help, open the FAQ hub.

Not at the moment. The formatter always uses two spaces per nesting level. If your project uses tabs, run a find and replace on leading spaces in your editor after copying.

Every text node is written on a separate line under its parent tag. Browsers treat that extra whitespace as a single space, so an inline element like b or a in the middle of a sentence can occasionally gain a visible gap. Check spacing around inline tags before you commit.

No. It indents what you give it. A missing closing tag shows up as indentation that never steps back out, which is often the quickest way to spot it. The HTML Validator names those problems explicitly.

View more FAQs

Related tools

View all

CSS Formatter

Format and pretty-print CSS.

Open

JS Formatter

Beautify JavaScript code.

Open

JSON Formatter

Beautify and validate JSON.

Open

XML Formatter

Format XML documents.

Open

Explore 321 free tools

Everything you need as a developer, marketer or creator - in one beautiful place.

Browse all tools