Reading minified HTML is like reading a one-line essay — every tag and attribute is jammed together with no visual structure. Try to debug a layout issue or insert a new element and you spend more time finding your place than fixing the bug. A formatter restores the structure: each block-level element on its own line, nested elements indented, long attribute lists wrapped, and closing tags aligned with their opens.
Our HTML formatter runs Prettier 3 in your browser. It auto-detects HTML5, Vue single-file components, Svelte, Astro, Angular, and Handlebars templates. Configurable: indent width, attribute-per-line wrap threshold, void-element style (<br /> vs <br>), and whether to wrap long lines. Paste any size, get clean output, copy or download.
Prettier HTML options that matter
| Option | Default | When to change |
|---|---|---|
printWidth |
80 | 100–120 if you have many attributes per element |
tabWidth |
2 | 4 only if matching legacy code |
htmlWhitespaceSensitivity |
“css” | “strict” if rendering depends on inline whitespace |
singleAttributePerLine |
false | true for very wide attribute lists |
bracketSameLine |
false | true to keep > at end of last attribute line |
endOfLine |
“lf” | “crlf” only for Windows-only repos |
The whitespace-sensitivity setting (the option you’ll actually want to think about)
HTML treats whitespace inconsistently. Inside a <p>, multiple spaces collapse to one. Inside a <pre>, every space is preserved. Between two inline elements (<span>a</span> <span>b</span>), the space between affects layout. Prettier’s htmlWhitespaceSensitivity option controls how aggressively the formatter rearranges whitespace:
- “css” (default): respect CSS
displaydefaults. Block-level elements get their own lines; inline elements stay on the same line where whitespace would matter. Best for most modern pages. - “strict”: never break a line where doing so would add or remove whitespace that affects rendering. Safest but produces longer lines.
- “ignore”: format aggressively, ignoring the impact on rendering. Use only if you control the CSS and know your inline elements have
white-spacerules that override the default.
Most pages format cleanly with the default. If you see layout shifts after formatting, switch to “strict” and reformat.
How to format HTML in your browser
- Open the HTML formatter
- Paste your HTML or drop in a
.htmlfile - Pick the parser (auto-detect usually works): html, vue, angular, handlebars, svelte
- Adjust print width and tab width to match your project
- Click Format — output appears with syntax highlighting
- Copy or download
Templating-language support
Prettier handles plain HTML, but real codebases often have templating syntax mixed in. Prettier 3 supports:
- Vue: single-file components (
.vue) with<template>,<script>,<style>blocks formatted independently. - Svelte:
.sveltefiles including{#if}/{#each}blocks and reactive declarations. - Angular:
*ngIf,*ngFor, and binding syntax ([prop],(event)) preserved. - Handlebars / Mustache:
{{…}}and{{#each}}blocks indented like HTML elements. - Astro: via the prettier-plugin-astro plugin.
For JSX (React), use the JavaScript Formatter instead — JSX lives in JS files and the JS parser handles both.
Common gotchas
- Whitespace inside
<pre>and<textarea>is preserved. Prettier doesn’t touch their content. If yours looks wrong, the issue was already in your source. - Self-closing void elements: Prettier 3 outputs
<br>(HTML5 default) not<br />(XHTML). To force XHTML style, post-process or use a different tool — there’s no built-in option in Prettier 3. - Comments above tags get attached to them. Prettier may move comments slightly to keep them tied to the right element. Usually fine; occasionally surprising.
- Custom Web Components are formatted like regular HTML elements. A
<my-button>with attributes wraps the same way<button>does. No special handling needed. - Don’t format AI-generated HTML and ship it without checking. AI tools sometimes produce
<div>…<span>…</div>with mismatched tags; the formatter happily produces beautifully indented broken HTML. Validate with the W3C validator after formatting. - Inline event handlers stay inline. Inline
on*attributes (onclick,onload) aren’t reformatted. Use external script tags for anything non-trivial.
When NOT to use a browser HTML formatter
For a real codebase, install Prettier locally (npm i -D prettier), commit a .prettierrc, and configure your editor to format on save. That eliminates formatting drift between developers. Use this browser tool for one-off snippets, copied HTML from a CMS or AI assistant, scraped markup you need to inspect, and pages built without a build pipeline. Don’t run the formatter on minified production HTML and re-deploy — keep source and minified output as separate artefacts.
Frequently asked questions
What’s the difference between an HTML formatter and a beautifier?
Same thing, different name. “Formatter” is the modern term (Prettier, dprint); “beautifier” is older (jsbeautify, HTML Tidy). Both reformat messy or minified markup into readable, indented output.
Can I format Vue, Svelte, or Astro components?
Yes. Prettier 3 handles Vue single-file components, Svelte files, Angular templates, and Astro components natively. Auto-detection picks the parser from file extension; you can override manually for paste-mode input.
Will formatting change how my page renders?
With the default htmlWhitespaceSensitivity: "css", no — Prettier respects CSS display rules and only adds whitespace where it doesn’t affect rendering. Edge cases involving custom white-space CSS may need htmlWhitespaceSensitivity: "strict" to be safe.
Can I unformat (minify) HTML with this tool?
No — formatting and minifying are opposite operations. For minification, use the HTML Minifier. Format while editing; minify before deploying.
Is my HTML uploaded?
No. Prettier runs in your browser via WebAssembly. Pasted markup never reaches our servers — useful for proprietary or pre-release pages.
Can I save my Prettier config?
Yes. Settings persist in your browser’s localStorage between sessions. There’s also a “Copy as .prettierrc” button that exports your settings as JSON ready to drop into a project root.
Related tools and guides
![HTML Formatter: Beautify HTML with Prettier [2026]](https://simpletool.io/blog/wp-content/uploads/2026/05/html-formatter.png)
![Make PDF Look Scanned: Browser-Only Converter [2026]](https://simpletool.io/blog/wp-content/uploads/2026/05/make-pdf-look-scanned.png)
![Lorem Ipsum Generator: Placeholder Text in Seconds [2026]](https://simpletool.io/blog/wp-content/uploads/2026/05/lorem-ipsum-generator.png)
![JSON Tree Viewer Online: Validate, Format, Search [2026]](https://simpletool.io/blog/wp-content/uploads/2026/05/json-tree-viewer-online.png)
![HTML Entity Decoder & Encoder: Escape HTML Safely [2026]](https://simpletool.io/blog/wp-content/uploads/2026/05/html-encoder-decoder.png)
![Image Color Picker Tool: Sample HEX, RGB & HSL [2026]](https://simpletool.io/blog/wp-content/uploads/2026/05/image-color-picker-tool.png)
