Skip to content
Free tool

HTML Formatter

Turn messy HTML into clean, indented code, or minify it and escape special characters. Your code stays in your browser.

How to use the HTML formatter

01

Paste your HTML into the first box.

02

Choose an indent size, then press Format.

03

Read through the result, then copy it.

Annotated screenshot for “How to use the HTML formatter” with the key button circled

An example

Before:

<ul><li><a href="/">Home</a></li><li>About</li></ul>

After pressing Format:

<ul>
  <li><a href="/">Home</a></li>
  <li>About</li>
</ul>

Links and bold text stay on the same line as the words around them, because adding a line break there can add a visible space on the page.

Screenshot or photo supporting “What it leaves alone” (HTML Formatter)

What it leaves alone

Anything inside <pre>, <textarea>, <script> and <style> is kept exactly as you wrote it, because changing spaces there can change how the page works or looks. Use a dedicated tool such as Prettier if you also want to format CSS and JavaScript.

The formatter does not check for mistakes. If a tag is missing or in the wrong place, run the page through the W3C validator. New to HTML? Start with our HTML guide.

Should you minify HTML?

It helps a little. Servers normally compress HTML before sending it, so removing spaces saves less than you might expect. Large images and unused scripts usually matter far more. Keep a readable copy of your code for editing, and minify only the version you publish.

Code editor screenshot illustrating “Should you minify HTML?”
FAQ

HTML Formatter questions, answered

Short, honest answers to the questions people ask most about this topic.

Is my code sent to a server?

No. Formatting happens in your browser, and nothing is saved.

It should not. The formatter only adds space around block elements and leaves pre, textarea, script and style content as it is. Check the result if your CSS uses white-space rules on block elements.

Formatting makes code easier to read. Validating checks it for errors. You need a validator to find mistakes.

Escape it when you want to show code as text on a page, for example in a tutorial. Escaping in a browser tool is not a security fix: a real website must escape user input in its own code.

Next step

More free tools

Find tools for images, text, code, search and speed, or plan your budget with the cost calculator.