Developer Tools
Free HTML Beautifier Online
Beautify and format HTML with proper indentation. Makes compressed or messy HTML readable.
HTML Beautifier: Reading and Reformatting HTML Markup
HTML beautification is the process of taking compressed, inconsistently indented, or machine-generated HTML and reformatting it with clean, depth-based indentation that makes the document's structure immediately readable. Minified HTML is optimal for production delivery — it transfers faster and reduces Time to First Byte — but it is nearly impossible to read or debug. The HTML Beautifier converts it back into a structured, human-readable form in one step.
When You Need to Beautify HTML
The need to reformat HTML arises in several common developer scenarios:
- CMS and framework output — content management systems, static site generators, and server-side frameworks often produce minified HTML in production. When debugging a rendering issue, reading the raw response is much easier after formatting.
- Third-party widgets and embeds — chat widgets, analytics dashboards, and marketing tools inject minified HTML into your page. Beautifying the injected markup helps you understand what they're adding and why it might conflict with your styles.
- Email templates — HTML email clients receive minified templates. Reformatting them makes it possible to trace which table cell corresponds to which visual element and to identify deliverability issues.
- API responses and scraped content — some APIs return HTML fragments or full pages. Beautifying the response makes it possible to identify the data you need and write accurate selectors.
- Inherited codebases — templates committed without formatting, or formatted with a different style guide, benefit from a clean reformat before editing.
Block vs Inline Elements: The Core Distinction
The most important decision an HTML formatter makes is whether to place each element on its own line or keep it inline with adjacent content. This decision is not arbitrary — it follows the HTML specification's block/inline model.
Block elements are elements that the browser renders in their own layout box: div, section, article, aside, header, footer, main, nav, p, ul, ol, li, table, tr, td, th, all heading levels (h1–h6), form, fieldset, blockquote, pre, figure, and more. Placing these on their own lines with indentation makes the document's structural hierarchy visible at a glance.
Inline elements are elements that flow within text: a, span, strong, em, b, i, code, kbd, abbr, cite, time, mark, label, img, input, button. Placing these on new lines would introduce whitespace text nodes between them and adjacent text, which the browser renders as visible spaces. A link moved to its own line would appear with a space before and after it in rendered output.
<!-- Breaking an inline element onto its own line changes rendered output -->
<!-- Before beautification (correct rendering): -->
<p>Visit <a href="/docs">documentation</a> for details.</p>
<!-- Incorrect beautification (adds unwanted spaces): -->
<p>
Visit
<a href="/docs">documentation</a>
for details.
</p>
<!-- Correct beautification (inline stays inline): -->
<p>Visit <a href="/docs">documentation</a> for details.</p>Indentation Styles
The beautifier supports three indentation styles, matching the conventions used by different teams and tools:
- 2 spaces — the default for most web projects and frameworks. Used by Prettier (the most widely adopted code formatter), Google's HTML style guide, and the majority of open-source front-end codebases. Minimises indentation depth for deeply nested HTML.
- 4 spaces — common in teams that use four-space indentation across all languages. Provides more visual separation between indent levels at the cost of wider lines in deep nesting.
- Tabs — preferred by developers who configure their editor's tab width individually. A team using tabs can each view the same file with their preferred visual indent width (2 for compact display, 4 for traditional, 8 for maximum separation). Tabs also compress better — a 16-space indent (four levels × four spaces) is one byte as a tab.
If you are reformatting HTML to commit to a repository, use whichever style is enforced by your project's EditorConfig or Prettier configuration.
Script and Style Blocks
Embedded <script> and <style> blocks contain JavaScript and CSS respectively. The HTML beautifier treats their content as raw text and indents each non-empty line to the current nesting depth, which gives a rough structural alignment with the surrounding HTML. The content itself is not parsed or reformatted as code.
For full formatting of embedded scripts and styles, copy their content into the dedicated tools: the JavaScript Minifier (beautify mode) for JavaScript, and the CSS Minifier (beautify mode) for CSS. You can then paste the formatted content back into the appropriate block.
HTML Validation vs Beautification
Beautification is a purely cosmetic operation — it changes indentation and line breaks without modifying the document's content or structure. It does not validate your HTML, fix broken markup, or correct nesting errors. A document with unclosed tags, duplicate IDs, or invalid element nesting will be reformatted with the same errors present.
If you suspect structural errors in your HTML, use the W3C Markup Validation Service at validator.w3.org. For accessibility issues (missing alt attributes, heading level skips, unlabelled form controls), use the axe DevTools browser extension or the accessibility audit in Chrome DevTools Lighthouse.
Prettierrc and Editor Formatting
If your goal is to establish consistent HTML formatting across a project rather than a one-off reformat, the right tool is Prettier with a .prettierrc configuration file. Prettier integrates with VS Code, WebStorm, and most other editors via extensions, and can be run as a pre-commit hook via lint-staged.
// .prettierrc
{
"printWidth": 100,
"tabWidth": 2,
"useTabs": false,
"htmlWhitespaceSensitivity": "css"
}The htmlWhitespaceSensitivity option controls how Prettier handles inline element whitespace — the same block vs inline distinction described above. The "css" value (default) uses the element's CSS display property to determine whether it is block or inline, which is the most accurate approach.
Reading Minified HTML from DevTools
When inspecting a page in Chrome DevTools, the Elements panel always shows formatted HTML regardless of what was delivered over the network — the browser's DOM representation is always structured. If you want to see the raw HTML as delivered, use the Network panel, find the document request, and click the Response tab. That response is often minified. Paste it into this beautifier to read it with the same structural clarity as the Elements panel.
The Source panel in DevTools also shows the raw HTML source. Right-click the page → View Page Source for a new tab with the unformatted response, which you can then paste directly into the beautifier.
HTML Formatting in Build Pipelines
Consistent HTML formatting in a team context is best enforced automatically rather than manually:
- Prettier with lint-staged — run
prettier --write '**/*.html'as a pre-commit hook on staged files using lint-staged and Husky. Every committed HTML file is formatted according to the project's Prettier configuration. - EditorConfig — an
.editorconfigfile at the repository root sets indent style, indent size, line endings, and trailing newline behaviour for all file types including HTML. Most editors respect EditorConfig without plugins. - CI formatting check — run
prettier --check .in CI to fail the build if any file is not formatted. This enforces the standard without requiring developers to remember to format before pushing.
FAQ
Common questions
What does the HTML beautifier do?
The beautifier parses HTML and reformats it with consistent depth-based indentation. Block-level elements (div, section, article, p, ul, li, table, tr, td, h1–h6, head, body, etc.) each appear on their own line, indented by their nesting depth. Inline elements (a, span, strong, em, img, code) stay on the same line as adjacent content to avoid introducing visible whitespace into rendered text.
When would I need to beautify HTML?
Common scenarios: reading minified HTML from a CMS, email template, or API response; debugging a layout issue where the nesting structure is unclear; auditing HTML output from a server-side renderer or third-party widget; reviewing scraped content; understanding an inherited codebase where templates were committed without formatting.
What indent style should I choose?
Two spaces is the most common convention for HTML (used by Prettier's default HTML formatter, Google's HTML style guide, and most web frameworks). Four spaces is common in teams that use four-space indentation throughout their codebase. Tabs are preferred by developers who use variable-width tab display and rely on editor tab-width settings to control visual indentation.
How does the beautifier handle <script> and <style> blocks?
Script and style content is treated as raw text. The beautifier indents each non-empty line of script/style content to the current depth, which gives a rough structural alignment. For full JavaScript or CSS formatting, copy the content of those blocks into the JavaScript Minifier (beautify mode) or CSS Minifier (beautify mode).
Does it handle inline elements correctly?
Yes. Inline elements — a, span, strong, em, b, i, u, s, code, kbd, samp, small, sub, sup, abbr, cite, q, mark, time, var, label, button, img, input, select, textarea — stay inline with their surrounding text. Moving them to new lines would introduce visible whitespace between words in the rendered page.
Does the beautifier validate or fix broken HTML?
No. The beautifier reformats what it receives without correcting structural errors. Unclosed tags, mismatched tags, and invalid nesting are passed through as-is. For HTML validation, use the W3C Markup Validation Service (validator.w3.org) or the HTML validation built into browser DevTools.
Can I use this on HTML email templates?
Yes. Email clients often send minified HTML. Pasting it into this tool will reformat it so you can read the structure, identify problematic elements, or adapt the layout. Note that email HTML often uses table-based layouts with inline styles — the beautifier handles these correctly.
Is my HTML sent to a server?
No. All processing runs entirely in your browser using a pure JavaScript tokenizer. Your markup is never uploaded, transmitted, or stored anywhere. The tool works offline once the page is loaded.
More in Developer Tools