HTML Formatter
Beautify and format HTML. Clean up messy or minified markup with proper indentation.
What is an HTML Formatter?
An HTML formatter (also called an HTML beautifier) automatically reformats your markup into clean, consistently indented code — making messy or minified HTML easy to read and maintain. It is powered by Prettier running entirely in your browser.
How to Format HTML Online
- Paste HTML into the Input pane, or click Upload to load a file.
- Choose 2, 4, or 6 space indentation — the output updates when you click Format.
- Enable ⚡ Live to auto-format as you type (400 ms debounce).
- Enable Auto-comment to inject section labels above structural blocks.
- Click Format to beautify your HTML.
- Use Copy or Download to save as
formatted.html. - Click Explain with AI for a plain-English breakdown of the HTML structure.
Auto-Comment — What Does It Do?
When Auto-comment is enabled, the formatter scans your HTML after beautifying and inserts descriptive comments above major structural elements like <header>, <nav>, <main>, <footer>, and <div> blocks with meaningful id or class names (e.g. class="sidebar" becomes <!-- ── Sidebar ─── -->).
Indentation Guide
- 2 spaces — the most common convention; used by Google, Airbnb, and most style guides.
- 4 spaces — preferred by Microsoft, Bootstrap, and many legacy projects.
- 6 spaces — occasionally used for deeply nested templating systems.
HTML Formatter vs. HTML Minifier
Formatting expands HTML for human readability during development. HTML Minification does the opposite — it strips all whitespace for the smallest possible production file. Use the formatter in dev; minify before deploy.
Common Errors
- Void elements with content —
<br>,<img>,<input>cannot have children. Prettier will flag these. - Unclosed tags — missing
</div>or</p>causes unexpected nesting in the formatted output. - Inline JS/CSS — Prettier also formats embedded
<script>and<style>blocks.
Keyboard Shortcuts
Ctrl + /— Toggle HTML comment on selected lineTab/Shift+Tab— Indent / dedent selectionCtrl + Z— Undo ·Ctrl + Y— Redo
Related Tools
- HTML Minifier — compress HTML for production
- HTML Validator — validate HTML against W3C standards
- CSS Formatter — beautify CSS stylesheets
- JavaScript Formatter — format JS with Prettier
Is My Code Sent to a Server?
No — formatting runs entirely in your browser using Prettier. Your code never leaves your machine.