HTML Beautifier
Turn unreadable HTML into neatly indented code. Each block element goes on its own line, and short inline content stays together so the result is easy to scan.
Beautify messy HTML with clean indentation, or minify it to save space. Paste your code and get instant results. Fast, free and no signup.
Your code is formatted inside your browser. We never send, save or store what you paste.
Add messy, minified or unindented HTML to the input box.
Beautify or minify, then pick the indent, line width and comments.
Copy the clean result or save it as an HTML file.
Looking for a free HTML formatter? Paste your code into our online HTML beautifier and instantly turn messy, minified or badly indented markup into clean, readable HTML with consistent indentation. Switch to minify mode to remove extra whitespace and comments for a smaller file. You can choose 2 spaces, 4 spaces or tabs, set the maximum line width, and decide whether to keep or remove comments. The tool works as an HTML formatter, HTML prettifier, HTML indenter and HTML minifier in one, runs entirely in your browser, and needs no signup. Whether you are cleaning up a template, reading code copied from a web page, or preparing HTML for production, this free online HTML code formatter saves time and makes your markup easier to read, review and maintain.
This free HTML formatter and HTML prettifier was designed for everyday use. Maybe you copied the source of a page and it is one long line, a template from a teammate has random indentation, or you need a small, minified version to paste into an email or a CMS. A good online HTML formatter is the quickest solution. It works as an HTML beautifier, HTML indenter, HTML code formatter and HTML minifier in one page, so you can format HTML code online on Windows, Mac, Linux, Android and iPhone without installing an editor plugin.
Turn unreadable HTML into neatly indented code. Each block element goes on its own line, and short inline content stays together so the result is easy to scan.
Remove line breaks, extra spaces and optional comments to make your HTML smaller. The tool keeps the spaces that matter between inline elements and leaves pre-formatted text untouched.
Formatting changes whitespace only. Your tags, attributes and text stay the same, and everything happens in your browser, so your code is never uploaded.
An HTML formatter, also called an HTML beautifier or prettifier, is a tool that rewrites HTML code with consistent line breaks and indentation so that its structure is easy to see. HTML ignores most extra whitespace, so developers can lay out their code however they like without changing how the page looks. Formatting does not change what your page does. It only changes how the source code is arranged, which makes it easier to read, debug, compare and edit.
Formatting HTML with this tool takes only a few steps.
Beautifying makes code easier for people to read by adding line breaks and indentation. Minifying does the opposite: it removes unnecessary whitespace and, optionally, comments so the file is smaller. Use beautified HTML while you are writing, reviewing and debugging. Use minified HTML when you want to reduce file size for a live website. Many projects keep the readable version as the source and generate the minified version for production.
Indentation is a matter of style, and teams often follow a shared standard. Two spaces keep deeply nested HTML compact, four spaces make structure stand out more, and tabs let each developer choose how wide indentation looks in their editor. Pick the option that matches your project, so formatted code stays consistent with the rest of your files.
In almost all cases, no. Browsers treat any run of spaces and line breaks as a single space, so adding indentation does not change the rendered page. The tool takes extra care with the exceptions. Content inside pre and textarea elements is kept exactly as written, and whitespace between inline elements such as links, spans and bold text is preserved as a single space. In rare cases, such as inline-block layouts that depend on the exact gaps between elements, changing whitespace can shift spacing slightly, so check the result in your browser.
The formatter treats block elements such as div, section, ul, li, p and table as structure. Each one is placed on its own line with its children indented below it. Inline elements such as a, span, strong, em, code and img flow together with text, so they stay on the same line and wrap only when a line becomes longer than your chosen width. This keeps paragraphs readable instead of splitting every link and bold word onto its own line.
Code inside style and script tags is re-indented to match the surrounding HTML, but it is not reformatted or minified. This keeps your CSS and JavaScript safe, because changing whitespace inside them can break template strings or comments. If you need to beautify or minify CSS and JavaScript themselves, use a dedicated formatter for those languages.
Minified HTML is smaller, which can reduce the amount of data a visitor has to download. The savings are usually modest on pages that are already compressed with gzip or Brotli, but they can add up for large pages, email templates and embedded snippets. This tool removes whitespace between tags, collapses repeated spaces and can remove comments. It does not minify the CSS and JavaScript inside your page, rename attributes or remove optional tags.
A formatter arranges code, but it does not validate or repair it. If your HTML has unclosed tags, stray closing tags or invalid nesting, the formatted output may look odd because it reflects the structure the tool could read. The tool handles common cases such as list items and paragraphs that are not explicitly closed, but you should still run important pages through an HTML validator and fix errors in the source.
The tool has only a few settings, and each one changes the layout of the code without changing the page it creates.
| Setting | Choices | What it does |
|---|---|---|
| Mode | Beautify or Minify | Beautify adds line breaks and indentation. Minify removes extra whitespace and puts the code in a compact form. |
| Indentation | 2 spaces, 4 spaces or Tab | Sets how far each nested level is moved to the right. |
| Line width | 80, 100, 120 characters or no wrapping | Sets how long a line of text and inline tags can grow before it wraps. |
| Remove comments | On or off | Deletes HTML comments from the output when turned on. |
This example shows how a one-line snippet is arranged. Block elements get their own lines, and short inline content stays together.
Before:
<div class="card"><h2>Title</h2><p>Hello <a href="/about">world</a></p><ul><li>One</li><li>Two</li></ul></div>
After (2 spaces):
<div class="card">
<h2>Title</h2>
<p>Hello <a href="/about">world</a></p>
<ul>
<li>One</li>
<li>Two</li>
</ul>
</div>
The tags, attributes and text are identical. Only the whitespace between them has changed, so the page looks the same in the browser.
If the formatted result does not look the way you expect, one of these causes is usually behind it.
| Problem | Likely cause | How to fix it |
|---|---|---|
| Odd indentation in the output | An unclosed or wrongly nested tag in the source | Fix the tag in your source and format again. The tool arranges what it can read, it does not repair HTML. |
| Everything is still on one line | Minify mode is selected | Switch the mode to Beautify. |
| A line is very long | Line width is set to No wrapping | Choose 80, 100 or 120 characters. |
| Spacing between inline items changed | The layout depends on exact gaps between inline elements | Check the result in a browser, and keep the original if the gap matters. |
| CSS or JavaScript did not change | The tool re-indents style and script tags but does not reformat them | Use a dedicated CSS or JavaScript formatter for those languages. |
| Comments disappeared | Remove comments is turned on | Turn the option off to keep comments. |
Our HTML formatter runs in your web browser, so you can format and minify HTML on Android, iPhone, Windows, Mac and Linux without installing anything. Whether you search for an HTML formatter for Chrome, an HTML beautifier for Mac or a quick way to tidy code on your phone, the steps are the same: open the page, paste your code 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 secrets such as API keys, passwords and private URLs from code before you paste it.
Formatting HTML is often one step in a bigger workflow. These related free tools make the rest of the job easier:
Our HTML formatter is free to use with no registration, no watermark and no limits. Everything runs in your browser, so your code stays on your device. It works on desktop, tablet and mobile.
Quick answers to common questions about formatting, beautifying and minifying HTML code online.
An HTML formatter, or beautifier, rewrites your HTML with consistent line breaks and indentation so the structure is easy to read. It changes how the code is laid out, not what it does.
Paste your HTML into the input box, keep the Beautify mode selected, and choose your indentation and line width. The formatted code appears instantly, ready to copy or download.
Beautifying adds line breaks and indentation to make code readable. Minifying removes extra whitespace, and optionally comments, to make the file smaller. Use beautified code for editing and minified code for production.
Almost never. Browsers collapse extra whitespace, and the tool keeps pre and textarea content exactly as written. In rare layouts that depend on exact gaps between inline elements, spacing can change slightly, so check the result.
It re-indents code inside style and script tags to match your HTML, but it does not reformat or minify the CSS or JavaScript itself. Use a dedicated formatter for those languages if you need that.
No. It arranges the code it can read but does not validate or repair it. Unclosed tags or invalid nesting may produce an odd layout in the output, so fix errors in your source and check pages with an HTML validator.
No. The formatting runs entirely in your browser, and your code is not uploaded, saved or shared.
Format and minify HTML here, then use the HTML minifier, the HTML encoder, the HTML to Markdown converter or the CSS minifier in seconds. Explore free developer tools to format, convert and debug your code in one place.
Explore All Developer Tools →