HTML beautifier

Paste minified or messy HTML and get clean, indented markup. Block elements go on their own lines, inline text stays together, and pre, textarea, script and style are left untouched. Free, in your browser.

How to use it

  1. Paste your HTML in the Your HTML box.
  2. Choose the style in Indentation: 2 spaces, 4 spaces or Tab.
  3. Click Copy or Download to use the Formatted HTML.

Complete guide to formatting HTML

When you need an HTML beautifier

HTML copied from a browser's "view source", exported by a page builder, generated by a script or minified for production is often one unbroken line. Finding a missing closing tag or the element you want to edit in that is slow. A beautifier puts each block element on its own line and indents children under their parents, so the structure of the page becomes visible at a glance. It is also useful before comparing two versions of a template or pasting markup into documentation.

How the formatting works

The tool walks through your markup and decides, tag by tag, where line breaks and indentation go. Block-level elements such as div, p, ul, li and h1 go on their own lines. Inline elements such as a, b, span and em stay in the flow of the text, so a sentence with a link is not split into pieces. Void tags such as br, img, meta and input do not add a level of indentation, and common optional closing tags such as those of li, p and td are understood. The contents of pre, textarea, script and style are never touched, because changing their whitespace could change what the page shows or how the code runs. It does not validate the markup, and nothing is uploaded: it all runs in your browser.

Worked example

  1. Paste this into Your HTML:

<div class="box"><h1>Hello</h1><p>Some <b>bold</b> and <a href="/x">linked</a> text.<br>New line</p><ul><li>One</li><li>Two</li></ul></div>

  1. Leave Indentation on 2 spaces.
  2. The Formatted HTML is:

<div class="box">
  <h1>Hello</h1>
  <p>
    Some <b>bold</b> and <a href="/x">linked</a> text.<br>
    New line
  </p>
  <ul>
    <li>One</li>
    <li>Two</li>
  </ul>
</div>

The paragraph is broken into lines at the br and its inline children keep their place, while each list item sits one level inside the list. Choosing 4 spaces or Tab changes only the width of each level.

Tips and common mistakes

  • If the result looks oddly indented, check the source for a tag that was never closed or closed in the wrong order. Because the tool formats without validating, broken markup shows up as broken indentation, which is a quick way to find the problem.
  • Whitespace between inline elements can matter on screen. The beautifier keeps inline content together, but always check the page after pasting formatted code back, especially inside buttons and table cells.
  • Formatted code is for reading and editing. When publishing, shrink it with the HTML minifier.
  • Inline script and style blocks are kept exactly as they are. To tidy the CSS inside, copy it into the CSS beautifier.

Related tools

If you need to display markup as visible text, the HTML entities encoder converts angle brackets and quotes safely. For XML, see the XML formatter.

Questions

Does it change how the page looks?

It only adds line breaks and indentation between block elements. Inline content such as links and bold text stays on the same line, and the content of pre, textarea, script and style is not touched.

What about tags without a closing tag?

Void tags such as br, img, meta and input are handled, and common optional closing tags such as li, p, td and option are understood.

Does it validate my HTML?

No. It formats what you give it and does not report errors. Broken markup may be indented in unexpected ways.

Is my HTML uploaded anywhere?

No. The formatting runs in your browser and nothing is sent or stored.