HTML Beautifier
Beautify HTML online for free — paste minified or messy HTML — including inline CSS and JavaScript and get clean, consistently indented code. Choose 2 spaces, 4 spaces or tabs, then copy or download. Powered by js-beautify; runs 100% in your browser.
100% private — everything runs in your browser. Conversion happens on your device; nothing is uploaded.
Formatting uses the open-source js-beautify library and runs entirely in your browser, so private code is never uploaded.
How to beautify HTML
- Paste your HTML (or open a .html file).
- Pick the indentation you use.
- Click “Beautify” — pasting also formats automatically.
- Copy the formatted code or download it.
What you can use it for
- Make one-line HTML from a CMS or email builder readable
- Indent nested markup to spot unclosed tags
- Format HTML before editing templates
- Tidy code copied from DevTools or page source
More free tools
Building for the web?
Format, minify, convert and generate code with our free, private developer tools.
See all free tools →Frequently asked questions
How do I format HTML?
Paste the code and click “Beautify”. Indentation, line breaks and spacing are rebuilt consistently, without changing what the code does.
Is beautifying the opposite of minifying?
Yes. Minifying strips whitespace for production; beautifying adds it back so people can read it. To minify again, use our HTML Minifier.
Does it format CSS and JavaScript inside HTML?
Yes. Code inside <style> and <script> tags is formatted too.
Can I control line length?
Yes — choose to wrap long lines at 80 or 120 characters, or leave them unwrapped.
Is my code uploaded?
No. Formatting runs in your browser with the open-source js-beautify library, so private code never leaves your device.
Is the HTML beautifier free, and can I use the formatted code commercially?
Yes. The beautifier is free to use with no account, and there's no usage limit. The output is your own code with new whitespace, so you can use it in personal or commercial projects without giving credit. Formatting is done by the open-source js-beautify library under the MIT licence, which covers the formatter itself, not your code.
Will beautifying change how my page looks?
It shouldn't. The beautifier only changes whitespace and line breaks; it doesn't rewrite tag names, attributes or text. Content inside <pre> and <textarea> tags is left exactly as it was, and inline tags such as <b>, <em> and <span> stay on the same line as the words around them, so no new gaps appear inside sentences.
Which files can I open, and how do I save the result?
Click Open file to load a .html, .htm or .txt file from your device; it's formatted as soon as it opens. You can also paste code straight into the box. When it's done, click Copy to put the formatted code on your clipboard, or Download to save it as formatted.html. Changing the indent or wrap setting reformats the code straight away.
Does it keep my comments and blank lines?
Yes. HTML comments stay where they are, and blank lines you added between blocks are kept, up to two in a row; longer gaps are shortened to two blank lines. Block elements such as <div>, <ul>, <li> and <p> each go on their own line, indented one level deeper than their parent, using 2 spaces, 4 spaces or a tab.
Can I format a complete HTML document?
Yes. Paste the whole file, from <!DOCTYPE html> to </html>. The <head> and <body> are indented inside <html>, CSS in <style> tags is split into one property per line, and JavaScript in <script> tags gets its own indentation. JSON-LD blocks (script type application/ld+json) are laid out as readable JSON, and inline SVG is indented like any other markup.
Why is nothing formatted, or why does the indentation look off?
If you see “The formatter failed to load”, the js-beautify library didn't download from its CDN; refresh the page and try again. If you see “Could not format”, the message after it gives the reason. If the last lines never return to the left edge, look for a tag that was opened but not closed, such as a missing </div>, because the beautifier keeps your tags as written.
Is an HTML formatter the same as an HTML beautifier?
On this page, yes: the HTML Beautifier is also our HTML formatter. Both names describe turning minified or messy markup into code with consistent indentation and block elements on their own lines, so it's easy to read and edit. For the opposite job, stripping whitespace to make a file smaller for production, use our free HTML Minifier.