Format
Rewrites your HTML with each element on its own line and nested tags indented. Turns minified or messy markup into clean, readable code.
<ul><li>One</li><li>Two</li></ul>After<ul>
<li>One</li>
<li>Two</li>
</ul>Paste minified or messy HTML and get it back with each element on its own line and everything indented. Or go the other way and minify your markup to make it smaller. Everything runs in your browser, so your code stays on your device.
HTML is often shipped minified, with all the whitespace removed so it loads faster, which makes it very hard for a person to read. A formatter, also called a beautifier, does the reverse: it rewrites the markup with each element on its own line and nested tags indented, so the structure is clear. This tool formats your HTML for reading and can minify it again when you are ready to ship. It changes only the spacing, never what the page shows.
Rewrites your HTML with each element on its own line and nested tags indented. Turns minified or messy markup into clean, readable code.
<ul><li>One</li><li>Two</li></ul>After<ul>
<li>One</li>
<li>Two</li>
</ul>Removes comments and the extra spaces and line breaks between tags to make the file smaller. Good for shipping HTML to production.
<ul>
<li>One</li>
</ul>After<ul><li>One</li></ul>Breaks very long lines so no single line runs off the screen. Leave it off to keep each element on one line no matter how long it gets.
One very long line of
attributes...AfterBroken onto several
readable linesChoose 2 or 4 spaces for each level of nesting, so the formatted HTML matches the style used in the rest of your project.
2 spaces or 4 spacesAfterYour choice per levelA formatter helps whenever markup is hard to read or needs to be smaller. These are the cases that come up most:
This tool uses js-beautify, a long-running open source beautifier. You can run it on your own files from the command line:
| To | Use |
|---|---|
| Format a file in place | npx js-beautify --type html --replace index.html |
| Choose 2 space indents | Add --indent-size 2 |
| Format on save in an editor | VS Code's built-in HTML formatter is also based on js-beautify, so Format Document gives similar results |
Beautifying changes spacing and line breaks only. It does not check that your HTML is valid, so a missing closing tag can still slip through. The W3C validator at validator.w3.org checks for that.
Working across stylesheets and markup? These formatters run the same way, right in your browser: