Small Tools
Frontend utility

HTML Formatter

Format HTML snippets with indentation for easier reading.

● This tool runs entirely in your browser. Your input is never uploaded to our servers.
Output
Your result will appear here…

How to use HTML Formatter

  1. Paste an HTML snippet or a whole document.
  2. Select Format.
  3. Check inline text and whitespace-sensitive blocks before you use the output.

Example

Input / settings:

<main><h1>Hello</h1><p>Welcome</p></main>

Output:

<main>
  <h1>Hello</h1>
  <p>Welcome</p>
</main>

An element that contains only text stays on a single line. Formatting the output again returns the same text.

When to use

Overview

HTML Formatter puts each tag on its own line and indents child elements by two spaces. It works on the text of your markup, splitting it into tags, comments and text without building a document tree, so it neither validates nor repairs the HTML. Tag names, attributes and text are left as written; only the whitespace between them changes.

Supported input

HTML text

Output details

formatted HTML

Common mistakes

Practical tips

Privacy and security

This tool runs entirely in your browser. Your input is never uploaded to our servers. Formatting runs locally and only inserts or removes whitespace between tokens. It does not sanitize the markup, and the tool never renders or executes it, so formatted HTML is exactly as untrusted as the input.

References

Frequently asked questions

Does HTML Formatter validate or fix my markup?

No. It splits the text into tags and text and re-indents them, even when tags are missing or misplaced.

Can I change the indentation width?

No. Child elements are indented by two spaces, and this page has no indentation setting.

Does the formatter keep HTML comments?

Yes. A comment is kept on its own line. HTML Minifier is the tool that removes ordinary comments.

Related tools