What this HTML formatter does
Paste any HTML — a minified page source, an email template, a CMS export, a snippet copied from DevTools or a Vue, Handlebars, Jinja or EJS template — and press Format HTML or Ctrl+Enter. The markup is re-indented with 2 spaces, 4 spaces or tabs, long lines are wrapped at 80 or 120 characters if you want, and the CSS inside <style> and the JavaScript inside <script> are formatted too. Three tabs sit on the output side: the formatted code, a live preview of the page at phone, tablet or full width, and an Issues list that points at unclosed tags, duplicate IDs and missing alt text by line number.
Everything runs in this browser tab with the open-source js-beautify engine, bundled with the page rather than loaded from a CDN. Your markup is never uploaded, so it is safe to paste client templates, admin panels or pages behind a login. Once the page has loaded you can go offline, or install it as an app from the button at the top.
How the formatting works
HTML is not XML, so a good HTML beautifier has to understand the rules in the WHATWG HTML Living Standard rather than simply indenting every tag. This tool follows those rules:
- Void elements such as
<br>,<img>,<input>,<meta>and<link>never get an end tag and never increase the indent. - Inline elements such as
<a>,<b>,<span>and<code>stay inside their line of text, because adding a line break there would insert a visible space on the rendered page. - Whitespace-sensitive content in
<pre>and<textarea>is left exactly as written. - Template tags such as
{{ }},{% %}and<% %>are recognised and kept intact. - Attribute wrapping can be automatic, one attribute per line (good for long Tailwind or Bootstrap class lists and for clean Git diffs), aligned, or preserved as you wrote it.
Formatting only changes whitespace between tags. It does not reorder attributes, add missing tags or rewrite your markup the way a browser's parser would, so what you get back is still recognisably your code.
The Issues tab: a quick HTML checker
Every time you format or minify, the tool also scans the markup and lists problems with the line number. Click a line number to jump to it in the editor. It reports:
- Unclosed and mismatched tags — for example a
<div>that is never closed or a</section>that closes the wrong element. Elements whose end tag is optional in HTML (<p>,<li>,<td>,<tr>,<option>and a few others) are not flagged, because leaving those end tags out is valid. - Stray end tags that have no matching start tag, and end tags on void elements such as
</br>. - Duplicate
idvalues. An ID must be unique in a document; duplicates breakgetElementById, label/input pairing and in-page anchors. - Images without an
altattribute. WCAG 2.2 criterion 1.1.1 requires a text alternative for meaningful images, and an emptyalt=""for decorative ones. - Obsolete elements such as
<center>,<font>and<marquee>, and nested links. - Document basics for full pages: a missing
<!DOCTYPE html>(which switches browsers into quirks mode), a missinglangon<html>, no<title>, no charset and no viewport meta tag.
This is a fast first pass, not a full conformance checker. Before you ship an important page, also run it through the W3C Nu Html Checker, which implements the complete specification.
Live HTML viewer, safely sandboxed
The Live preview tab renders your HTML in an <iframe> with the sandbox attribute. By default scripts, forms, pop-ups and plugins are all blocked, so you can open markup from an unknown source without it running anything. If you need to see a script-driven widget, tick Run scripts: scripts are then allowed but the frame is still given a unique, opaque origin, so it cannot read this page, your cookies or your saved history. Use the 375 px, 768 px and full-width buttons to check a responsive layout at phone and tablet sizes without leaving the page.
Minify HTML without breaking it
Minify removes indentation and line breaks and collapses runs of spaces. It is deliberately conservative: whitespace is only removed next to block-level tags such as <div>, <p> and <li>, while a single space is kept between inline elements, because <b>Hello</b> <i>world</i> and <b>Hello</b><i>world</i> render differently. The contents of <pre>, <textarea>, <script> and <style> are left untouched; JSON-LD structured data is compacted safely. Comments are kept unless you tick Remove comments, and Internet Explorer conditional comments and <!--! … --> licence comments are always kept. The stats bar shows the size before and after.
Minifying HTML usually saves 5–20% before compression. Your server's gzip or Brotli compression saves far more, so turn that on first, and treat minification as an extra.
More actions
- Escape HTML entities turns
<,>,&and quotes into<,>,&and so on, so you can show code inside a blog post or a<pre>block. - Unescape entities does the reverse, which helps when HTML arrives double-encoded from an API or a database.
- Extract plain text drops tags, scripts and styles and keeps paragraphs and line breaks. It is handy for counting the words on a page or pasting text into a document.
Typical uses
Developers use an HTML formatter to read the minified output of a framework or a page builder, to review a pull request, or to tidy a template before committing it. Bloggers and WordPress users use it to clean up markup pasted from Word or Google Docs. Email marketers use it on table-heavy newsletter templates, where one missing </td> breaks the layout in Outlook. Students use the preview as a quick online HTML viewer for practice exercises. SEO specialists use the Issues tab to spot missing titles, alt text and language attributes.
Tips for clean HTML
- Start every page with
<!DOCTYPE html>,<html lang="en">and<meta charset="utf-8">. - Use semantic elements —
<header>,<nav>,<main>,<article>,<footer>— instead of nesting<div>elements. - Give every image a meaningful
alt, andwidthandheightattributes to avoid layout shift. - Keep each ID unique and prefer classes for styling.
- Pick one indentation style for the team and format before every commit, so diffs only show real changes.
Privacy, offline use and limits
All work happens locally. Drafts and the last 12 inputs are stored only in this browser's localStorage, and you can clear them from the History dialog. The tool has been tested with documents larger than 1 MB, with Hindi and emoji text, and with broken markup. Formatting is best-effort on badly broken HTML: if tags are mismatched, fix the issues listed first, then format again.
Sources and standards
- WHATWG, HTML Living Standard — §13 The HTML syntax (void elements, optional end tags, raw-text elements).
- W3C, Nu Html Checker — the reference conformance checker.
- W3C WAI, WCAG 2.2 Success Criterion 1.1.1 Non-text Content (alt text).
- MDN Web Docs, <iframe sandbox> — how the preview is isolated.
- js-beautify (MIT licence), the formatting engine, bundled locally with this page.
Frequently asked questions
Is my HTML uploaded to a server?
No. Formatting, checking and previewing all run in this browser tab with a locally bundled copy of js-beautify. You can disconnect from the internet after the page loads.
Is the live preview safe for unknown HTML?
Yes. The preview is a sandboxed iframe. Scripts, forms and pop-ups are blocked unless you tick Run scripts, and even then the frame has an opaque origin, so it cannot read this page, cookies or storage.
Does formatting change how my page looks?
No. Inline elements stay on their line and pre/textarea content is untouched, so the rendered page stays the same. Only indentation between block elements changes.
Why isn't a missing </p> or </li> reported?
The HTML standard makes the end tags of p, li, td, tr, option and a few other elements optional, so leaving them out is valid HTML. Unclosed div, span, a, section and similar elements are reported.
Is this a full HTML validator?
It is a fast first-pass checker for the most common mistakes. For full conformance against the HTML Living Standard, also use the W3C Nu Html Checker.
Can it format Vue, Handlebars, Jinja or PHP templates?
Yes for the HTML parts. Template tags like {{ }}, {% %} and <% %> are detected and kept intact. PHP logic itself is not re-indented.