HTML Beautifier
Beautify minified HTML or minify pretty HTML. Properly indented, easy to read.
What is an HTML beautifier?
An HTML beautifier turns a single compressed line of markup into an indented tree, so you can see which element sits inside which. MavexTech’s HTML Beautifier has two modes: Beautify puts every tag and text node on its own line with two-space indentation, and Minify collapses the whitespace between tags to make the HTML compact. It runs entirely in your browser, which makes it safe for email templates, CMS exports and client pages you cannot upload elsewhere.
How to use it
- Pick a mode — Beautify to expand, Minify to compress. Switching tabs re-processes the input.
- Paste your HTML — a snippet, a template or a full page.
- Click Process to refresh the output.
- Copy the result into your editor, CMS or email builder.
How it works
Beautify reads the markup tag by tag (quoted attribute values may contain >):
- an opening tag is printed at the current depth and the depth goes up by one level (two spaces);
- a closing tag reduces the depth by one and is printed at that level;
- void and self-closing tags —
<br>,<hr>,<img>,<input>,<meta>,<link>,<source>,<wbr>,<col>,<area>,<track>,<embed>,<base>,<param>and anything ending in/>— as well as the doctype and HTML comments do not change the depth; - text between tags is trimmed and printed on its own line at the current depth;
- the content of
<pre>and<textarea>is kept exactly as written, and<script>/<style>code keeps its own line breaks and is only re-indented as a block.
Minify collapses every run of spaces, tabs and line breaks into a single space and removes it completely next to block-level tags such as <div>, <p>, <ul> and <li>. A space between inline tags (<b>bold</b> <i>it</i>) is kept so words do not run together. <pre> and <textarea> content is left untouched and <script>/<style> code is only trimmed, never joined onto one line.
Worked example (output from the live tool)
The default input <div class="container"><h1>Hello World</h1><p>This is a sample paragraph.</p><ul><li>Item 1</li><li>Item 2</li></ul></div> (122 characters) beautifies to:
<div class="container">
<h1>
Hello World
</h1>
<p>
This is a sample paragraph.
</p>
<ul>
<li>
Item 1
</li>
<li>
Item 2
</li>
</ul>
</div>The beautified version is 186 characters — the extra 64 are line breaks and indentation. Minify mode turns it back into the original 122-character line. A second test: a 48-character list written over four lines with a double space inside an item minifies to <ul><li>One</li><li>Two words</li></ul> (39 characters).
Which tags change the indentation
| Markup | Beautify behaviour |
|---|---|
<div>, <p>, <ul>, <li>, <span>, <b> … | Indent one level until the matching closing tag |
<br>, <hr>, <img>, <input>, <meta>, <link>, <source>, <wbr>, <col>, <area>, <track>, <embed> | Printed on their own line, no extra indent |
Any tag ending in /> (e.g. <source />) | Treated as self-closing, no extra indent |
<!DOCTYPE html> and HTML comments | Printed on their own line, no extra indent |
<pre>, <textarea>, <script>, <style> | Content kept as written (script/style re-indented as one block) |
When to beautify and when to minify
- Beautify HTML copied from a page builder, an email platform export or a View Source window so you can find a broken or missing closing tag.
- Beautify before a code review, so the nesting is obvious.
- Minify a small HTML snippet for a widget, an embed code or a custom-HTML block where line breaks get converted into unwanted
<br>tags or extra spacing. - For whole sites, let your build pipeline or CDN handle minification and compression; it can also process CSS and JavaScript safely.
Tips
- Indentation drifting further and further right usually points to an unclosed element in your HTML — use it as a quick structure check.
- For the CSS and JS inside a page, use the CSS Beautifier and JS Beautifier separately.
- Text encoding problems such as
&amp;are easier to fix with the HTML Encoder/Decoder.
Limitations & notes
This is a simple tag-by-tag formatter, not a full HTML parser. Beautify puts text inside inline tags such as <b> or <a> on separate lines, which can add visible spaces between words when the result is rendered, so use it for reading rather than for publishing. Content of <pre> and <textarea> is kept exactly, and inline <script>/<style> code is not minified (use the JS Beautifier or CSS Beautifier for that). Minify does not remove HTML comments. Nothing you paste is uploaded.
Frequently asked questions
Will minification break my HTML?
Plain markup is fine. The minifier keeps the space between inline elements, leaves pre and textarea content untouched and does not squash inline scripts or styles onto one line, so their line breaks and // comments keep working.
Can I un-minify HTML from a website?
Yes. Paste the minified HTML into Beautify mode to get an indented version. Anything the site removed during its own minification, such as comments, cannot be recovered.
How much smaller does minified HTML get?
It depends on how much indentation the source has. In the example on this page the beautified 186 characters minify to 122, about 34 percent smaller. Server compression such as gzip or Brotli usually saves more than whitespace removal.
Does it handle the doctype and HTML comments?
Yes. The doctype declaration and HTML comments are printed on their own line and do not change the indentation of the lines that follow.
Does the beautifier fix invalid HTML?
No. It only adds line breaks and indentation. Missing closing tags are not added, but they become easy to spot because the indentation no longer returns to the left margin.
What indentation does it use?
Two spaces per nesting level, which is a common default in HTML style guides and editors.
Is my HTML uploaded?
No. Both modes run in your browser, so templates containing customer data or unreleased content stay on your device.
Related tools
CSS Beautifier · JS Beautifier · Code Minifier · HTML Encoder/Decoder · XML Formatter · Markdown to HTML
