HTML Formatter
Format and beautify messy or minified HTML into clean, indented markup with Prettier, including embedded CSS and JavaScript. Runs locally in your browser.
Runs in your browser · Nothing uploadedFree · No sign-up
Something not working, or missing a feature? Send feedback
About the HTML Formatter
Minified or hand-edited HTML is hard to read and review. The HTML Formatter re-indents markup with Prettier so nesting is obvious, without changing what the page renders.
Everything runs in your browser, so your input is never uploaded to a server.
How to use the HTML Formatter
- Paste HTML or open an .html file.
- Choose the indentation and the line width at which long lines wrap.
- Copy or download the formatted markup.
Example
Input
<ul class="nav"><li><a href="/">Home</a></li><li><a href="/about">About</a></li></ul><p>Hello <b>world</b></p>
Result
<ul class="nav"> <li><a href="/">Home</a></li> <li><a href="/about">About</a></li> </ul> <p>Hello <b>world</b></p>
Block elements get their own lines. Inline elements such as <a> and <b> stay inline, because adding whitespace around them could change the rendered text.
Common mistakes
- Expecting every tag on its own line. Whitespace between inline elements is visible on the page, so <b>10</b>USD is left on one line on purpose. Splitting it would add a space to the text.
- Mismatched closing tags. Browsers silently repair <span>Hello</div>; the formatter stops at the unexpected closing tag and gives its line and column. End tags HTML lets you omit, such as </p>, are added for you.
- Template syntax. Razor (.cshtml), Blade, Twig or Handlebars tags are not HTML. Format the rendered HTML, or keep template code out of the input.
Works well with the HTML Formatter
- HTML Viewer: preview the markup, or the HTML a .cshtml view renders, safely in a sandbox.
- HTML Minifier: compress the HTML for production.
- CSS Formatter: tidy the stylesheet that goes with it.
Frequently asked questions
Will formatting change how my page looks?
Formatting only changes whitespace between tags. In rare cases whitespace inside inline elements matters; Prettier keeps it where it affects rendering.
Can it format embedded CSS and JavaScript?
Yes. Code inside <style> and <script> tags is formatted along with the markup.
Is my HTML uploaded?
No. Formatting happens in your browser with Prettier.
Can I change the line width?
Yes. Lines are wrapped at 100 characters by default; set Line width between 40 and 200.
Can I format .cshtml (Razor) files?
Only the HTML parts. Razor code such as @model, @if and @foreach is not HTML, so it is kept as text and may be indented oddly. To see the page a view produces, copy the rendered HTML from your browser and open it in the HTML Viewer.
Guides and tutorials
- Web Development
How to View and Preview HTML Online: Snippets, Files and Email Templates
View HTML online: paste code to render a live preview, open an .html file, check an email template, and fix blank or unstyled previews. No upload or install.
· 4 min read
- Code Quality & Workflow
Why Code Formatting Matters: Setting Up Prettier for Your Team
Why consistent formatting speeds up reviews, how Prettier works, and a team setup: config, format on save, CI, ESLint and reformatting a codebase safely.
· 5 min read
- Web Development
How to Preview HTML Code Online Safely: Sandboxed iframes Explained
Preview and render HTML code without risk: how sandboxed iframes, srcdoc and CSP isolate untrusted markup, why scripts stay off, and fixes for broken previews.
· 6 min read
- Web Development
HTML Meta Tags That Matter for SEO and Social Sharing
The meta tags every page needs: title, description, canonical, robots, viewport, Open Graph and Twitter Cards, with lengths, examples and tags to skip.
· 6 min read
Related tools
JSON Formatter
Format and beautify JSON with configurable indentation and optional key sorting. Errors are reported with exact line and column.
CSS Formatter
Format and beautify CSS, SCSS and Less online with Prettier. Turn minified or messy stylesheets into readable, consistently indented code in your browser.
JavaScript Formatter
Format and beautify JavaScript and JSX online with Prettier. Choose indentation, quotes, semicolons and line width; your code is formatted in your browser.
TypeScript Formatter
Format and beautify TypeScript and TSX online with Prettier, including types, generics and decorators. Choose indentation, quotes and semicolons.
PHP Formatter
Format PHP code online with Prettier for PHP (@prettier/plugin-php): PSR-12 braces, spacing and 4-space indentation. No install, and nothing is uploaded.
SQL Formatter
Format and beautify SQL queries online for MySQL, PostgreSQL, SQLite, SQL Server and more, with keyword casing and indentation options. Runs in your browser.