TheTools.World tool

HTML formatter online

Paste HTML to add readable indentation based on tag nesting, or minify it into a single compact line by removing whitespace between tags. This is a lightweight formatter for already well-formed markup, not a full HTML parser.

Format or minify HTML

Paste HTML to add readable indentation based on tag nesting, or minify it into a single compact line by removing whitespace between tags. This is a lightweight formatter for already well-formed markup, not a full HTML parser.

How to format or minify HTML

  1. Paste your HTML into the box.
  2. Leave Minify unchecked to indent, or check it to compact instead.
  3. Click Format HTML.
  4. Review the result for correct indentation, especially around any unusual or self-closing tags.
  5. Copy the result or download it as an .html file.

This formatter indents based on tag nesting depth using simple pattern matching; it does not parse or validate HTML the way a browser or a full HTML parser would, so it works best on already-reasonable markup rather than badly broken HTML.

What this formatter does and how it works

The formatter puts each tag on its own line, then indents each line based on how many unclosed opening tags came before it, increasing the indent after an opening tag and decreasing it after a matching closing tag. Self-closing tags (like <br/>), declarations, and comments don't affect the indent level. Minify mode does the reverse: it strips whitespace between tags to produce one compact line, which is useful when file size matters more than readability.

Best practices

Common mistakes to avoid

Real-world use cases

Limitations

This is a lightweight, pattern-based formatter, not a full HTML parser: it does not fix mismatched tags, does not understand HTML5 void elements beyond simple self-closing syntax detection, and does not reformat the contents of embedded <script> or <style> blocks as their own language. For production-grade formatting or validation, use a dedicated HTML parser/linter in your build pipeline.

Privacy

HTML you paste is processed locally in your browser. It is not sent to a server, logged, or stored. See the privacy policy for the site's full data handling approach.

Troubleshooting

Conclusion

Use this formatter for quick readability fixes on reasonably well-formed HTML, or to minify a snippet before embedding it elsewhere. For XML documents, use the XML formatter; for JSON, use the JSON formatter.

FAQ

Will this fix broken HTML?

No. It reformats whitespace and indentation based on tag patterns; it does not repair mismatched or unclosed tags.

Does it validate my HTML?

No. It only reformats whitespace. Use a dedicated HTML validator or linter to check for markup errors.

Does it format JavaScript or CSS inside script and style tags?

No. Content inside those tags is treated as plain nested text, not parsed as its own language.

Is my HTML uploaded anywhere?

No. Formatting happens locally in your browser, and your markup is not sent to a server.