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
- Paste your HTML into the box.
- Leave Minify unchecked to indent, or check it to compact instead.
- Click Format HTML.
- Review the result for correct indentation, especially around any unusual or self-closing tags.
- 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
- Use it for readability during development or code review, not as a substitute for an HTML validator.
- Check the indentation visually after formatting, especially for custom or unusual tags, since this is a lightweight pattern-based formatter rather than a full parser.
- Minify only for production output where file size matters; keep a formatted, readable copy for editing.
Common mistakes to avoid
- Expecting this to fix broken or invalid HTML. It indents based on tag patterns; it does not repair mismatched or unclosed tags.
- Formatting HTML that contains inline
<script>or<style>blocks with their own complex internal syntax, which this formatter treats as plain nested content rather than parsing the embedded language. - Relying on this as an HTML validator. It reformats whitespace only; it does not check for missing alt attributes, invalid nesting, or other HTML validity issues.
Real-world use cases
- Making minified HTML from an API or scraped page readable for review or debugging.
- Cleaning up HTML pasted from a rich text editor or CMS before committing it to source code.
- Minifying a small HTML snippet or email template before embedding it elsewhere.
- Quick formatting during code review without opening a full IDE.
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
- If indentation looks wrong in one section, check for a mismatched or unclosed tag just before that point.
- If a self-closing tag causes odd indentation, confirm it actually ends with
/>; tags without the trailing slash are treated as needing a separate closing tag. - If you need XML formatted instead, use the XML formatter, which uses the same indentation logic for XML documents.
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.
Related tools
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.