Beautify HTML
Turn messy or minified HTML into neatly indented code. Block elements get their own lines, while short text and inline tags stay together.
Beautify messy HTML with clean indentation, or minify it for production. Formats inline CSS and JSON too. Fast, free and no signup.
Add your code or upload an .html file.
Pick beautify or minify, the indent, line length and extra options.
Copy the clean code or download it as a file.
Looking for a free HTML beautifier? Paste your code and this HTML formatter rewrites it with clean line breaks and consistent indentation in an instant. It handles messy, one-line and minified HTML, formats the CSS inside style tags, tidies JSON-LD structured data, and keeps pre and textarea content exactly as it is. You can choose the indent size, the line length and whether to keep comments and blank lines. Need the opposite? Switch to Minify mode to compress your HTML for production. There is nothing to install, no account to create and no API: everything runs in your browser, so your source code stays private. It is a simple online tool for web developers, designers, students and SEO specialists who want readable, well-structured HTML.
This free HTML beautifier goes a little further than a basic indenter. Besides arranging your tags, it can also format the CSS inside style tags and the JSON-LD in structured data scripts, break long tags into one attribute per line and keep or drop comments and blank lines. People find it by searching for html beautifier, beautify html online, html pretty print, format html code or unminify html. It runs in your browser on Windows, Mac, Linux, Android and iPhone, so you can clean up a page source from any device.
Turn messy or minified HTML into neatly indented code. Block elements get their own lines, while short text and inline tags stay together.
Remove extra whitespace and optional comments to make your HTML smaller. CSS in style tags and JSON-LD are compressed too.
Style blocks and structured data scripts are formatted along with your markup, so the whole page is easy to read in one pass.
An HTML beautifier, also known as an HTML formatter, HTML prettifier or HTML indenter, is a tool that reformats HTML source code so that it is easy for people to read. Browsers do not care whether your HTML is on one line or on a thousand lines, but developers do. A beautifier adds line breaks and indentation that show how elements are nested, so you can see at a glance which tags belong together. The content and meaning of your page stay the same.
Here is a small piece of minified HTML and how it looks after formatting with a 2-space indent.
<div class="card"><h2>Title</h2><p>Hello <b>world</b>!</p><ul><li>One</li><li>Two</li></ul></div>
<div class="card">
<h2>Title</h2>
<p>Hello <b>world</b>!</p>
<ul>
<li>One</li>
<li>Two</li>
</ul>
</div>
Notice that block elements such as div, ul and li each get their own line and indentation level, while the short paragraph with a bold word stays on a single line.
These settings let you match the formatting style of your project.
| Option | What it does | Recommended |
|---|---|---|
| Indent size | 2 spaces, 4 spaces or tab | 2 spaces is the most common style for HTML |
| Wrap line length | Where long lines of text are wrapped, or no wrapping | 100 or 120 characters for readable code |
| Format CSS and JSON | Formats style tags and JSON-LD, re-indents other scripts | On |
| Keep blank lines | Keeps one blank line where your code had one | On to keep sections apart, off for the cleanest output |
| Break long tags | Puts each attribute on its own line when a tag is too long | On |
| Keep comments | Keeps HTML comments, or removes them when turned off | On to beautify, off to minify |
Beautifying and minifying are opposites, and most projects use both. Keep a readable version of your HTML while you build the site, and serve a minified version to visitors so pages are a little smaller. Smaller HTML can mean faster loading, which is good for user experience and for SEO.
| Mode | Result | Best for | Trade-off |
|---|---|---|---|
| Beautify | Readable code with line breaks and indentation | Editing, debugging, code review, learning | Larger file size |
| Minify | Removes extra whitespace and comments | Live pages, email size limits, faster loading | Hard to read |
Modern pages contain more than HTML tags. When Format CSS and JSON is on, the code inside style tags is split into rules and declarations with one property per line, and JSON inside script tags, such as JSON-LD structured data, is pretty-printed. Regular JavaScript is only re-indented to fit the page, because rewriting JavaScript safely needs a full parser. Content inside pre and textarea tags is never changed, since whitespace matters there.
If the beautified code does not look the way you expect, one of these settings or causes is usually the reason.
| Problem | Likely cause | How to fix it |
|---|---|---|
| The output is still one long line | Minify mode is selected | Switch the mode to Beautify |
| CSS inside style tags is not formatted | The Format CSS and JSON option is off | Turn the option on |
| Tags with many attributes stay on one line | Break long tags is off or the line length is high | Turn on Break long tags and choose 80 or 100 characters |
| Blank lines were removed | Keep blank lines is off | Turn the option on to keep one blank line between sections |
| Comments are missing | Keep comments is off | Turn the option on |
| Indentation looks odd in one area | A tag is unclosed or nested incorrectly in the source | Fix the tag in your source. A beautifier arranges code but does not repair it. |
Our HTML beautifier works entirely in your web browser, so it runs on Android, iPhone, Windows, Mac and Linux with nothing to install. Whether you need an HTML beautifier for Chrome, a quick format on your phone or a way to unminify a page source on a Mac, the steps are the same: paste the code, choose your settings and copy the result.
Your code is formatted inside your browser. It is not uploaded, saved or stored on a server, and it is gone when you close or refresh the page. As a general habit with any online tool, remove API keys, passwords and private links from the code before you paste it.
Beautifying HTML is often one step in a bigger workflow. These related free tools make the rest of the job easier:
This HTML code formatter is free to use as often as you like, with no signup and no watermark. It works completely in your browser, so your source code is never sent to our server or to another company. Beautify or minify your HTML, copy the result and keep building.
Find answers to common questions about formatting, beautifying and minifying HTML code.
An HTML beautifier, also called an HTML formatter or HTML prettifier, takes messy, minified or badly indented HTML and rewrites it with consistent line breaks and indentation. The tags, text and attributes stay the same. Only the layout of the code changes, so it becomes much easier to read, edit and debug.
Paste your HTML into the input box or upload an .html file. The formatted code appears instantly in the result box. Choose the indent size and the line length you prefer, then copy the result or download it as a file. To compress your code instead, switch to Minify mode.
Beautifying adds line breaks and indentation so people can read the code. Minifying does the opposite: it removes extra spaces, line breaks and optionally comments to make the file smaller, which can help pages load faster. Use the beautified version while you work and the minified version for the live website.
It should not. The formatter only changes whitespace between tags, and it keeps a single space between inline elements and text where one existed. Content inside pre and textarea tags is kept exactly as it is. In rare layouts that depend on exact whitespace between inline elements, compare the page before and after, as you would after any code change.
No. It formats the HTML you give it but does not repair mistakes or check it against the HTML standard. It tries to handle common cases such as optional closing tags for li, p, td and tr, but for errors like wrong nesting or missing attributes, use an HTML validator after formatting.
Yes, to a degree. CSS inside style tags is fully formatted, and JSON inside script tags, such as JSON-LD structured data, is formatted too. Regular JavaScript is re-indented to match the page but its code is not rewritten, so it always stays safe to run. When minifying, CSS is compressed and JavaScript is left untouched.
Yes. It is free, needs no signup and has no usage limit. All formatting happens in your browser, so your code is never uploaded to our server or sent to any third-party service. That makes it safe for private templates and client projects.
Beautify HTML here, then use the HTML minifier, the HTML encoder, the JSON formatter or the CSS minifier in seconds. Explore free developer tools to format, convert and debug your code in one place.
Explore All Developer Tools →