HTML Beautifier

Beautify HTML online: put block elements on their own lines and indent minified or one-line markup by its tag nesting. Free, in your browser.

Runs in your browser. Files never leave your device.
6 words · 70 chars

About the HTML Beautifier

Paste markup that is crammed onto one line, such as minified HTML, a CMS export or an email template, and this HTML beautifier puts each block element on its own line and indents it by how deeply it is nested. With the structure visible, a link, a class or a heading buried in a block of code is much easier to find.

The formatted version appears in the result box as you type. Tag names, attributes and text are kept as they were; what changes is the line breaks, the indentation and extra spaces between words.

How the HTML is laid out

The markup is read tag by tag with the open-source js-beautify formatter, which runs inside the page. It keeps a stack of open elements, so every closing tag is matched with its opening tag and lands at the same indent. Each level of nesting adds two spaces: a <li> inside a <ul> inside a <nav> sits four spaces in.

Block elements such as <div>, <p>, <ul>, <li>, <table> and <tr> start on a new line. Inline elements such as <a>, <b>, <span>, <img> and <br> stay on the line with the text around them, because a line break there could add a visible space on the page. The contents of <script> and <style> are formatted as JavaScript and CSS, and the contents of <pre> and <textarea> are copied exactly.

Before anything is formatted the input is checked for at least one HTML tag; if there is none, a warning is shown instead.

Assumptions and limits

  • Runs of spaces inside ordinary text are reduced to one, which matches what a browser shows. Line breaks you put inside a paragraph are kept.
  • Long lines are not wrapped, so a paragraph with a lot of text stays on one line.
  • It doesn't validate the markup. An unclosed <div> is formatted as it is, so the elements after it are indented as if they were inside it, which often helps you find the missing tag.
  • Tag and attribute names keep their case: <DIV CLASS=a> stays in capitals. Attribute values and quotes are not changed.
  • HTML comments are kept where they are in the markup.

Worked examples

Format a one-line navigation menu

An 82-character menu written on a single line becomes six lines. The <ul> is indented under <nav>, each <li> under the <ul>, and every closing tag lines up with its opening tag. The links stay inside their <li> lines because <a> is an inline element.

Input:
<nav><ul><li><a href="/">Home</a></li><li><a href="/blog">Blog</a></li></ul></nav>

Output:
<nav>
  <ul>
    <li><a href="/">Home</a></li>
    <li><a href="/blog">Blog</a></li>
  </ul>
</nav>

Re-indent HTML pasted from a page builder

When markup already has line breaks but uneven spacing, the old leading spaces are thrown away and replaced with indentation that follows the nesting, so both paragraphs sit two spaces inside the <div>.

Input:
<div>
      <p>One</p>
  <p>Two</p>
</div>

Output:
<div>
  <p>One</p>
  <p>Two</p>
</div>

Plain text pasted by mistake

If you paste a paragraph with no tags at all, the result box shows "No valid HTML tags or structure detected in input" rather than returning the same text, so you know the input wasn't HTML.

What happens to each part of the markup

In your HTMLIn the formatted result
Block tags: div, p, ul, li, table, tr, sectionOwn line, indented two spaces per nesting level
Inline tags: a, b, span, img, brKept on the line with their text
Closing tagsLined up with the matching opening tag
<script> and <style> contentsFormatted as JavaScript and CSS
<pre> and <textarea> contentsCopied exactly
Attributes, values, tag caseUnchanged
Several spaces in a row inside textOne space

How to use the HTML Beautifier

  1. Paste the HTML. Replace the sample markup in the Input Text box with your own code, from a single snippet to a full page.
  2. Read the formatted markup. The Result box shows the markup indented by nesting, updating each time you edit the input.
  3. Copy it. Press Copy and paste the formatted HTML into your editor, or use it to find the element you were looking for.

Frequently asked questions

How do I beautify minified HTML?

Copy the minified markup from the page source or your file, paste it into the input box and read the result. Every block element moves to its own line with an indent that shows what it sits inside, so a page that was one enormous line turns into an outline you can scroll and search.

Does the HTML beautifier change my content or attributes?

No. Tag names, attributes, class names, links and text are kept. The changes are line breaks between block elements, the indent at the start of each line and runs of spaces inside text reduced to one, which a browser would display as one space anyway.

Why are links and bold text not on their own lines?

Because they are inline elements. Putting a line break between a word and a link can add a visible space on the page, so the beautifier keeps <a>, <b>, <span>, <img> and similar tags on the line with their text, as code editors do.

Can I pretty print HTML email templates with it?

Yes. Email builders often export table-heavy HTML on very few lines. Formatting it puts each <table>, <tr> and <td> on its own line at the right depth, which makes it much easier to find a link, an image path or a colour you need to change.

Does it check whether my HTML is valid?

No. It doesn't report unclosed or misspelled tags; it only lays out what you paste. An unclosed element shows up as everything after it being indented one step too far. It does warn you when no HTML tags are found at all, which usually means the wrong text was copied.

Is my HTML code uploaded?

No. The beautifier is loaded with the page and runs in your browser, and nothing you paste is sent to a server or saved, so unpublished pages and client code stay private.

This tool runs entirely in your browser. What you enter or upload stays on your device and is never sent to our servers.