HTML Formatter

Format HTML with clean indentation.

Local Your input is processed locally in your browser. The first run loads the open-source Prettier library from this site; your input is not sent anywhere. Found a problem? Report an issue

What the HTML Formatter does

The HTML Formatter formats HTML with Prettier 3.3.3, an open-source code formatter, running in your browser. It supports HTML documents and fragments, respecting whitespace-sensitive inline elements.

HTML Formatter examples

The built-in sample

Input

<div><h1>Hello</h1><p>Some <b>text</b></p></div>

Output

<div>
  <h1>Hello</h1>
  <p>Some <b>text</b></p>
</div>

This is the input that the Load sample button fills in.

A whole document

Input

<!doctype html><html><head><style>a{color:red}</style><script>function f(){return 1}</script></head><body><p>Hi <b>there</b></p><pre> keep   this </pre></body></html>

Output

<!doctype html>
<html>
  <head>
    <style>
      a{color:red}
    </style>
    <script>
      function f(){return 1}
    </script>
  </head>
  <body>
    <p>Hi <b>there</b></p>
    <pre> keep   this </pre>
  </body>
</html>

Block elements are indented and the inline b element stays inside its sentence. The text inside pre is untouched. The contents of the style and script elements are indented but not re-formatted.

Each output was produced by running this tool on the input above it.

How it works

The code is parsed with Prettier's html parser and printed again from its syntax tree, using Prettier's default options: lines up to 80 characters and two-space indentation. The result therefore does not depend on how the input was laid out. If the code cannot be parsed, the parser's message with its line and column is shown instead of output.

Details and limits

  • Whitespace between inline elements is significant in HTML, and the formatter does not add or remove it. That is why closing brackets sometimes appear at the start of the next line: it breaks the line inside the tag instead of between the tags.
  • The contents of pre and textarea are never changed.
  • Code inside script and style elements is not re-formatted, because this page loads only the HTML part of Prettier. Format it with the JavaScript Beautifier or the CSS Beautifier.
  • Attribute values are given double quotes.

Questions

Is my data uploaded when I use HTML Formatter?

No. The tool runs in your browser, so what you paste or open is processed on your own device and is not sent to a server.

What does HTML Formatter do?

The HTML Formatter formats HTML with Prettier 3.3.3, an open-source code formatter, running in your browser. It supports HTML documents and fragments, respecting whitespace-sensitive inline elements.

How does HTML Formatter work?

The code is parsed with Prettier's html parser and printed again from its syntax tree, using Prettier's default options: lines up to 80 characters and two-space indentation. The result therefore does not depend on how the input was laid out.

Are there any limits I should know about?

Whitespace between inline elements is significant in HTML, and the formatter does not add or remove it. That is why closing brackets sometimes appear at the start of the next line: it breaks the line inside the tag instead of between the tags. The contents of pre and textarea are never changed.

Is there a size limit?

There is no fixed size limit. Everything happens on your device, so very large inputs depend on its memory and can take longer on a phone than on a computer.

Does it work on phones, and is it free?

Yes. It works in any current browser on Android phones, iPhones, tablets and computers. It is free and needs no account or sign-up.