HTML Beautifier: Format and Clean HTML Code Online
HTML Beautifier formats HTML with Prettier, the same engine VS Code uses, or minifies it with a fragment-aware minifier. Pick the indentation, tab width, print width, whitespace sensitivity and line endings, protect Jinja, Handlebars, ERB, PHP or Go template tokens so they survive untouched, then inspect the result as highlighted code, a sandboxed preview, a line diff or a list of markup issues. It runs entirely in your browser, so your markup stays on your device.
HTML Beautifier is an online HTML beautifier that formats markup with Prettier, the same engine VS Code uses, and minifies it with a small dependency-free minifier. Paste or drop in a full document or a bare fragment: Beautify re-indents and re-wraps the markup, Minify removes comments and collapses whitespace. Both run in your browser, so you can paste markup from a private project without it leaving your device.
Formatting is driven by the same options Prettier itself exposes. Indentation can be spaces or tabs, tab width and print width control line length, whitespace sensitivity decides how aggressively inline elements and significant spaces are rewritten, and the Advanced group adds line endings, one attribute per line, bracket placement, embedded CSS and JavaScript formatting, and void-element style. Presets set a whole combination in one click, and every option is described inline so you can see what it does.
Template syntaxes are the part a plain formatter gets wrong. A token such as {% if x %}, {{ user.name }}, <?php echo $x; ?> or <% ... %> is not HTML, so Prettier will happily split it across lines or rewrite the quotes inside it. Auto-detect finds those tokens and swaps them for placeholders before formatting, then puts them back and verifies each one is still intact. If a token cannot be verified, the input is returned unchanged rather than corrupted, and the tool tells you why. Templates with tokens inside attribute values or between table rows are exactly the cases this protects.
The output pane has four views. Code shows the result with syntax highlighting and line numbers. Preview renders it inside a sandboxed iframe with scripts disabled by default, so pasted markup cannot run code or reach the rest of the page. Diff compares the formatted output with your input line by line. Issues lists markup problems it can see - duplicate IDs, images without alt text, links without an href, inline event handlers, a missing doctype, lang or viewport, and deprecated tags - and clicking one selects that line. Minified output also reports the byte saving and a gzip estimate.
If you want the same formatting in your editor, the .prettierrc panel turns the current options into the matching config file and a ready-to-run Prettier command, so this page and your project cannot drift apart.
The HTML Beautifier runs entirely in your browser. Your input is processed on your own device; it is not uploaded, stored, or sent to a server, and after the page has loaded the tool works without a network connection. It is useful for developers and DevOps engineers who want to inspect, clean up, or share HTML without hand-reindenting it, and for anyone pasting markup from a tool they do not trust to reformat it correctly.
If you have several files, the batch panel formats up to 20 HTML files with the settings above and hands them back as a zip. Live formatting pauses above 300 KB; your input is never empty while that happens, and the manual format of a large document runs in a background worker so the page stays responsive while it works.
Step 1: Paste or drop your HTML into the tool. A full document and a bare fragment are both accepted.
Step 2: Choose Beautify to format the markup with Prettier, or Minify to strip comments and collapse whitespace.
Step 3: Set the options you care about: indentation, print width, whitespace sensitivity, line endings and void-element style. The Advanced group holds the less common ones; presets fill in a whole set at once.
Step 4: If your HTML contains template tokens, set Template syntax to Auto-detect. Jinja, Handlebars, ERB, PHP and Go tokens in attributes or between table rows are then protected from being reflowed.
Step 5: Format the HTML. Warnings appear above the output, and any template token that could not be verified leaves the input unchanged rather than corrupted.
Step 6: Switch between the Code, Preview, Diff and Issues views: highlighted source with line numbers, a sandboxed rendering, a line diff against your input, and the list of markup problems with the line each one starts on.
Step 7: Copy the result, download it, or copy the matching .prettierrc and Prettier command line so your editor and this page agree.
Use case: Make an unreadable, machine-generated HTML file easier to review before you commit it.
Use case: Protect a Jinja, Handlebars, ERB, PHP or Go template from being mangled by a formatter.
Use case: Minify a fragment such as a table row or a mail body without having a doctype wrapped around it.
Use case: Check a pasted snippet for duplicate IDs, images without alt text, links without href and inline event handlers.
Use case: Preview pasted markup in a sandbox, with scripts off, before you paste it anywhere else.
Use case: Compare your input with the formatted output in a line diff so you can see exactly what moved.
Use case: Export the equivalent .prettierrc so the same settings apply in your editor and CI.
Use case: Produce consistently indented output so a code review highlights real changes instead of whitespace noise.
Use case: Format a snippet before adding it to a bug report, so others can read it easily.