HTML Formatter

Paste HTML and an indented version appears below. Blocks get their own lines, the text inside a paragraph stays on one line, and nothing inside pre or textarea moves.

How it works

The formatter reads your HTML into a tree of elements, then writes it back with one block element per line, indented by how deeply it is nested.

Inline elements, such as links, bold text and spans, stay on the same line as the text around them. Moving them onto their own lines would add visible spaces to the page. A paragraph that fits in 80 characters stays on one line; a longer one gets its content on its own indented line.

pre and textarea content is copied as it is, because every space in it shows. Script and style blocks are re-indented as a block. The formatter runs on this page, and your HTML is not uploaded.

How to use it

  1. 1 Pick how to indent: 2 spaces, 4 spaces or tabs.
  2. 2 Paste your HTML into the first box. The formatted HTML appears in the second box as you type.
  3. 3 Press Copy result, or download it as a .html file.

Good to know

  • Formatting minified HTML before you read it makes a missing closing tag much easier to spot.
  • If your source left out optional closing tags, such as </li> or </p>, the formatted output writes them in. The page means the same thing either way.
  • To shrink the result again for production, use the HTML Minifier.

Browser support

  • Chrome 94 and later
  • Firefox 93 and later
  • Safari 16.4 and later
  • Edge 94 and later

These are the oldest versions with everything the tool uses. They are worked out from the tool itself, so they change when it does.

Version numbers checked on 2026-09-04.

Formatting one line of minified HTML, and the closing tags it never had

Take this line of minified HTML: a ul holding "<li>Tea<li>Coffee", then a closing </ul>, then a paragraph that says "Read the menu first." with "the menu" as a link, and then "<div>Open daily</div>". Everything is on one line. There is no </li> after Tea or Coffee, and no </p> after the paragraph. This is valid HTML. The standard lets you leave those closing tags out, and minifiers often do.

A browser reads it with a few rules. A new <li> closes the open <li> before it, so Tea and Coffee are two separate items. The </ul> closes the second item and the list. A <div> cannot sit inside a <p>, so when the browser meets <div>, it closes the paragraph first. The formatter uses the same rules. Its output has five lines for the list: <ul>, then <li>Tea</li> indented by two spaces, then <li>Coffee</li>, then </ul>. After that comes the paragraph on one line with a </p>, and then the div on its own line. The closing tags in the output are the ones the browser already assumed.

Look at the paragraph line: <p>Read <a href="/menu">the menu</a> first.</p>. The link stays on the same line as the words around it. That is deliberate. Between inline elements, a line break shows on the page as a space. If the formatter put the link on its own line, the browser would show a space where each line break is. Here that would be harmless, because there are spaces around the link already. In "un<b>believ</b>able" it would split the word in three. Keeping inline content together is the only way to be sure the page looks the same. When a paragraph is longer than 80 characters, its content goes on its own indented line inside the p, but it is never split across lines, except after a <br>.

Some content is never touched. A pre element shows every space and line break, so the formatter copies it exactly, even if its indentation does not match the lines around it. Text in a textarea is treated the same way. Script and style blocks are moved to the right depth as a whole, with their own lines kept as you wrote them.

The formatter has limits. It lays out HTML; it does not fix it. A closing tag with no opening tag is kept in place rather than dropped, so you can find it. It cannot see your CSS, so an element with white-space: pre set in a stylesheet may gain spaces. It does not reformat JavaScript or CSS line by line. And it does not keep the formatting quirks of your source, such as blank lines between sections. The goal is a layout you can read, not a copy of the original.

Frequently asked questions

Will formatting change how my page looks?

For normal HTML it should not. The formatter only adds line breaks next to block elements, where the browser ignores whitespace. It never splits text and inline tags across lines, and it leaves pre and textarea content alone. An element you made whitespace-sensitive with CSS is the exception, because the formatter cannot see your CSS.

Why did closing tags appear that were not in my HTML?

HTML lets you leave some closing tags out. A new <li> closes the one before it, and a new block closes an open <p>. The formatter follows the same rules as the browser and writes the closing tags in, so you can see where each element really ends.

Does it fix broken HTML?

No. It lays out what is there. A stray closing tag with no matching opening tag is kept where it was, so you can find it and fix it yourself.

Does it format the JavaScript and CSS inside the page?

It re-indents script and style blocks so they sit at the right depth, but it does not reformat the code inside them line by line.

Is my HTML sent to a server?

No. The formatter is JavaScript running on this page. Nothing you paste leaves your device.

Related tools

Your files are processed on your device and are not uploaded. You can verify this in your browser’s developer tools under the Network tab.