HTML Formatter
Turn messy HTML into clean, indented code, or minify it and escape special characters. Your code stays in your browser.
- Nothing is uploaded or stored
- No sign-up
How to use the HTML formatter
Paste your HTML into the first box.
Choose an indent size, then press Format.
Read through the result, then copy it.
- Format adds line breaks and indentation around block elements such as sections, lists and tables.
- Minify removes comments and extra spaces to make the code smaller.
-
Escape turns characters such as
<into<so you can show code on a page. - Unescape does the reverse.
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.
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.
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.
Will formatting change how my page looks?
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.
What is the difference between formatting and validating?
Formatting makes code easier to read. Validating checks it for errors. You need a validator to find mistakes.
When should I escape HTML?
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.
More free tools
Find tools for images, text, code, search and speed, or plan your budget with the cost calculator.