HTML Formatter
Clean up minified or messy HTML. Embedded <style> and <script> blocks are formatted too.
HTML
Formatted HTML
How to use the HTML Formatter
- Paste your HTML, open a .html file, or press Sample.
- Set indentation and line width in the options if the defaults do not suit your project.
- Press Format, or Ctrl + Enter. Errors show the line and column of the problem.
- Copy the result or download it as a .html file.
Example
<!doctype html><html><head><title>Hello</title><style>body{margin:0;font-family:system-ui}</style></head><body><nav><a href="/">Home</a><a href="/about">About</a></nav><main><h1>Hello</h1><p>Some <strong>text</strong>.</p></main><script>document.querySelector("h1").addEventListener("click",()=>alert("hi"))</script></body></html>What it does
- A real parser, not find-and-replace
- Your HTML is parsed into a syntax tree before printing, so nesting is always correct and invalid code is reported rather than mangled.
- Your style settings
- Choose 2 or 4 spaces or tabs, and a maximum line width. Settings are remembered on this device.
- Embedded CSS and JS
- Code inside <style> and <script> tags is formatted with the CSS and JavaScript formatters.
- Runs in your browser
- The formatter loads on demand and runs locally. Nothing you paste leaves your device.
Frequently asked questions
Which engine formats the HTML?
Prettier, the widely used open-source code formatter. It parses your HTML into a syntax tree and prints it again, so the output is consistent and the same input always gives the same result.
Is my code uploaded anywhere?
No. The parser and printer run in your browser. Your code is never sent to a server, logged or stored.
Why does inline text sometimes wrap oddly?
In HTML, whitespace between inline elements can change how a page looks. The formatter respects this by default. Set whitespace sensitivity to "ignore" in options if you prefer tidier output and know the spacing does not matter.
Will formatting change how my code behaves?
No. Prettier only changes whitespace, line breaks, quotes and similar layout details. If it cannot be sure a change is safe, it leaves the code as written.