Skip to content
Devtoolry

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

  1. Paste HTML or open an .html file.
  2. Choose the indentation and the line width at which long lines wrap.
  3. Copy or download the formatted markup.

Example

Indent minified markup

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