HTML Beautify — Online HTML Formatter and Pretty-Printer

🔒 Runs in your browser — nothing is sent to a server

HTML formatter that turns any compact, minified or hand-written HTML into a clean, indented document. Paste a Tailwind component, a server-rendered page, an email template or any HTML blob, and this HTML beautifier parses it through the browser's native `DOMParser`, then pretty-prints the tree with 2 or 4 spaces or tab indentation. `<pre>`, `<textarea>`, `<script>` and `<style>` content is preserved verbatim; inline tags like `<a>`, `<span>` and `<strong>` stay on the same line as their parent text; void tags (`<br>`, `<img>`, `<input>`) skip the closing tag. Everything runs 100% inside your browser; your input never leaves your device.

Content of <pre>, <textarea>, <script> and <style> is preserved verbatim.

Two-pane view: input and output side by side
Copied!

When to use an HTML beautifier

You reach for an HTML beautifier any time a one-line HTML payload arrives unreadable: debugging the response of an SSR endpoint, peeking inside a marketing email pulled from your ESP, untangling a Tailwind-laden component you copied from a template, comparing two server-rendered pages with `diff`, walking through an admin export, or preparing an HTML snippet for inclusion in documentation. The pretty-printed form is what most readers and tools expect, and what Prettier produces. Running the format in a browser-local tool keeps the payload off remote servers — important when the HTML carries tokens, internal URLs or PII.

How HTML beautifying works under the hood

HTML beautifying is a three-step pipeline. First the input is scanned for the DOCTYPE — it lives outside the document tree, so it is pulled aside before parsing. Second the input is fed through `new DOMParser().parseFromString(input, "text/html")`; the HTML parser is lenient, so almost any input parses. Third a recursive tree walker re-emits every element: inline tags stay inline with parent text, block tags get their own line, `<pre>`/`<textarea>`/`<script>`/`<style>` are preserved verbatim, boolean attributes are normalised to bare names, and long opening tags wrap onto multiple lines. Conditional comments are always kept; ordinary comments are kept by default. The whole pipeline runs inside the browser, so a multi-megabyte HTML document beautifies in milliseconds without leaving your tab.

Examples

Input
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Hello</title></head><body><h1>Atlas</h1><p>Welcome to <strong>free-converter.online</strong>.</p></body></html>
Output
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Hello</title>
  </head>
  <body>
    <h1>Atlas</h1>
    <p>Welcome to <strong>free-converter.online</strong>.</p>
  </body>
</html>
HTML beautifier — minified document with head and body
Input
<section class="card"><h2>Products</h2><ul><li>Atlas <em>(new)</em></li><li>Vesper</li></ul></section>
Output
<section class="card">
  <h2>Products</h2>
  <ul>
    <li>Atlas <em>(new)</em></li>
    <li>Vesper</li>
  </ul>
</section>
Pretty print HTML — list with mixed inline content
Input
<article data-tool="html beautify"><h1>html formatter tool</h1><p>Beautify HTML online inside your browser.</p></article>
Output
<article data-tool="html beautify">
  <h1>html formatter tool</h1>
  <p>Beautify HTML online inside your browser.</p>
</article>
Format HTML online — payload that names the tool itself
Input
<div><pre>  if (a < b) {
    x = 1;
  }</pre><script>const y = 2;</script></div>
Output
<div>
  <pre>  if (a &lt; b) {
    x = 1;
  }</pre>
  <script>const y = 2;</script>
</div>
Beautify HTML online — script and pre preserved verbatim

FAQ

How do I beautify an HTML document?

Paste the compact or minified HTML into the input above, pick an indent (2 spaces by default, 4 spaces or tab) and click Beautify. The HTML formatter parses your input through the browser's native `DOMParser`, walks the document tree and re-emits every block element on its own line. Inline tags stay on the same line as their parent text.

What is HTML beautifying or pretty-printing?

HTML beautifying — also called pretty-printing — reformats compact HTML by adding line breaks and indentation so a human can scan the structure. The data is unchanged: every element, attribute, text node, comment and script body stays exactly as it was; only the cosmetic whitespace around block tags differs. Beautified HTML renders identically to the original in any browser.

Does the formatter touch the content of <pre>, <script> and <style>?

No. The HTML beautifier treats `<pre>`, `<textarea>`, `<script>` and `<style>` as preserve-content tags. Their inner content — including all whitespace, line breaks and indentation — is emitted byte-for-byte. This keeps preformatted code blocks readable, leaves embedded JavaScript and CSS untouched, and avoids breaking carefully laid-out `<textarea>` defaults.

How does the formatter handle inline tags like <a>, <span> and <strong>?

Inline tags stay on the same line as their parent text — exactly the way Prettier and prettier-plugin-html do it. So `<p>Hello <strong>world</strong>!</p>` is left as a single line because pulling `<strong>` onto its own line would change the rendered whitespace. Block tags (`<div>`, `<p>`, `<section>`, `<h1>`) get their own line and indent.

How are HTML void elements like <br> and <img> rendered?

Void elements have no closing tag in HTML5: `<br>`, `<img src="…">`, `<input type="text">`, `<meta>`, `<link>`, `<hr>`. The default Self-close style is HTML5 — bare opening tag, no `/`. Switch to XHTML mode if your downstream needs `<br/>`, `<img/>` for an XHTML or JSX-style template. The list of void tags is the WHATWG HTML standard one.

Are boolean attributes like disabled and checked preserved correctly?

Yes. When the HTML beautifier sees an empty value on a known boolean attribute (`disabled`, `checked`, `required`, `selected`, `readonly`, `autoplay`, `multiple` and the rest of the WHATWG list), it emits the bare attribute name — `<input disabled>` rather than `<input disabled="">` or `<input disabled="disabled">`. That matches what every modern formatter and browser inspector outputs.

How are conditional comments handled?

`<!--[if IE]> … <![endif]-->` conditional comments are always preserved, even when "Remove comments" is ticked. They were the IE-specific way to gate legacy stylesheet links, and stripping one would change the rendered page in older Outlook clients and in IE-targeted email templates. Plain `<!-- comment -->` annotations are preserved by default and removed only when the option is on.

How are long attribute lists wrapped?

Short opening tags stay on one line. When an opening tag would exceed 120 characters and the element has more than one attribute, the formatter breaks each attribute onto its own indented line and aligns the closing `>` underneath the tag name. Diff-friendly and readable for SVG, button and form elements with a dozen `data-*` and ARIA attributes.

Glossary

HTML (HyperText Markup Language)

HTML is the standard markup language of the web, defined by the WHATWG HTML Living Standard. Pages, emails, server-rendered components and email templates all ship as HTML. An HTML formatter reformats compact HTML without changing its meaning — only the cosmetic whitespace around block tags differs between minified and pretty-printed forms.

HTML formatter

An HTML formatter is any tool or function that takes HTML input and emits it as a string with controlled indentation and line breaks. Browser `DOMParser` plus a custom tree walker, IDE plugins like the JetBrains formatter, command-line `tidy -indent` and editor packages such as Prettier all qualify. Browser-local formatters keep secrets and tokens in HTML emails or admin pages off remote servers.

Inline vs block elements

HTML elements split into inline (`<a>`, `<span>`, `<strong>`, `<em>`, `<code>`, `<small>`) and block (`<div>`, `<p>`, `<section>`, `<article>`, `<h1>` through `<h6>`, `<ul>`, `<table>`). A correct beautifier keeps inline tags on the same line as the surrounding text, because the whitespace there is rendered. Block tags each get their own line and indent.

Void element

A void element is an HTML element that cannot contain children — `<br>`, `<img>`, `<input>`, `<hr>`, `<meta>`, `<link>`, `<area>`, `<base>`, `<col>`, `<embed>`, `<source>`, `<track>`, `<wbr>`. In HTML5 they have no closing tag and no trailing slash. XHTML uses the self-closing form `<br/>`. The HTML beautifier offers both styles via a Self-close option.

Boolean attribute

A boolean HTML attribute is an attribute whose mere presence enables a behaviour — `disabled`, `checked`, `required`, `selected`, `readonly`, `autoplay`, `controls`, `loop`, `multiple`, `open`, `hidden`. The HTML5 spec accepts three forms (`disabled`, `disabled=""`, `disabled="disabled"`) but the canonical form is the bare name. A modern HTML formatter normalises to the bare name.

Conditional comment

A conditional comment — `<!--[if IE]> … <![endif]-->` — is an Internet Explorer specific extension that targeted IE 5–9 with version-gated markup. Although IE is gone, the construct still appears in legacy pages and Outlook email templates that rely on it for fallback stylesheets. A safe HTML beautifier always preserves conditional comments, even when stripping ordinary `<!-- … -->` annotations.

Related tools