Developer

HTML Formatter

Beautify and indent raw HTML code

Loading interactive tool…

Embed this tool on your site

About this tool

HTML Formatter takes compressed or single-line HTML and rewrites it with two-space indentation. Paste markup and click Format HTML: whitespace between tags is removed, then every tag and every text node goes on its own line, one level deeper inside each open element and one level back at its closing tag. Attributes are copied exactly as written. Doctype and comment lines and the void elements br, hr, img, input, meta and link do not add a level. The formatter is a simple tag scanner rather than a full HTML parser, so the output is for reading structure, not for replacing your source: inline elements such as <strong> or <a> are split onto separate lines, content inside <pre>, <script>, <style> and <textarea> is re-indented like everything else, and tags written with /> (common in SVG) or other void elements such as <source> push the indentation one level too deep. It runs entirely in the browser so no markup reaches a server.

Why use it

  • See the Nesting at a Glance: Deep or irregular nesting is invisible in compressed markup. One element per line with two-space indentation shows the hierarchy immediately.

  • Spot Unclosed Tags: When indentation keeps drifting right or never returns to the left margin, an element is probably unclosed or a void element was written as a container.

  • Attributes Untouched: Attribute names, values and order are copied exactly as written, so ids, classes and data-* values stay easy to search for.

  • Readable Snippets for Bug Reports: Turn a single-line HTML blob copied from DevTools or a CMS export into an indented outline you can paste into an issue or chat.

  • Safe for Sensitive Markup: HTML from admin templates, email campaigns, or internal tools often contains tokens and IDs that shouldn't leave your network. Everything runs locally in your browser — nothing is sent to any server.

How to use

  1. Paste your raw or minified HTML into the HTML to format box.
  2. Click 'Format HTML' to indent it with two spaces per nesting level.
  3. Read the nesting in the Formatted HTML box to see which elements sit inside which.
  4. Click 'Copy result' to copy the formatted HTML.
  5. Click 'Clear' to empty both boxes.

When it helps

  • When pasting HTML exported from a CMS, page builder, or design tool that outputs single-line markup.
  • When reviewing an HTML email or landing-page export and you need to find where each section starts and ends.
  • When debugging a third-party HTML snippet and needing to understand its nesting structure before modifying it.
  • After copying HTML from browser DevTools to paste into documentation or a bug report in readable form.
  • When checking whether a minified snippet has balanced opening and closing tags.
  • When learning how a page is structured by reading its markup as an indented outline.

Examples

Minified card fragment

Input
<div class="card"><h2 class="card-title">Hello World</h2><p>Read <a href="/more">more</a></p></div>
Expected result · Scroll for more
<div class="card">
  <h2 class="card-title">
    Hello World
  </h2>
  <p>
    Read
    <a href="/more">
      more
    </a>
  </p>
</div>

Simple list

Input
<ul><li>One</li><li>Two</li></ul>
Expected result
<ul>
  <li>
    One
  </li>
  <li>
    Two
  </li>
</ul>

Full document

Input
<!DOCTYPE html><html><head><title>Demo</title></head><body><p>Hi</p></body></html>
Expected result · Scroll for more
<!DOCTYPE html>
<html>
  <head>
    <title>
      Demo
    </title>
  </head>
  <body>
    <p>
      Hi
    </p>
  </body>
</html>

Tips

  • If indentation drifts to the right and never comes back, look for a self-closing /> tag or a void element such as <source> just above where the drift starts.
  • Keep your original markup for production; the formatted copy drops whitespace between tags and splits inline elements, which can change how text renders.
  • If the formatted output looks strange, check for mismatched or unclosed tags — the formatter exposes nesting bugs that are invisible in compressed markup.
  • Format HTML before diffing two versions manually; indentation-normalised files produce diffs that highlight only real content changes.
  • For Jinja, Handlebars, or other template languages mixed with HTML, format the rendered output rather than the source template to see the actual structure.

Frequently Asked Questions

Does the formatter change any attribute values or text content?
Attribute values are copied exactly. Text keeps its words, but whitespace between tags is removed and each text node goes on its own line with added indentation, which can change how inline text and <pre> blocks render. Use the output for reading, and keep your original for production.
Will it handle HTML5 documents with <!DOCTYPE html> and <head> correctly?
Yes. A doctype line is kept at the top without adding a level, and <html>, <head> and <body> children are indented beneath their parents.
What happens to inline elements like <span> or <a> inside a paragraph?
They go on their own lines like every other element. <p>This is <strong>bold</strong> text</p> becomes seven lines, with the text and the <strong> tag indented inside the paragraph.
Does the formatter handle self-closing tags like <input> and <br>?
br, hr, img, input, meta and link are recognised as void elements: they do not add an indentation level and no closing tag is added. Other void elements, such as source, area or wbr, and tags written with />, are treated as containers, so the lines after them are indented one level too deep.
Can I format an HTML fragment rather than a full page?
Yes. Paste any snippet — a single <div> tree, a <nav> block, or a partial template — no full document wrapper is required.
How does the formatter handle pre and script tags where whitespace matters?
They are not protected. Content inside <pre>, <script>, <style> and <textarea> is indented like other text, whitespace between tags inside <pre> is removed, and a < character inside a script is read as the start of a tag. Leave those blocks out, or check them by hand after formatting.
Does it support SVG or MathML markup embedded in HTML?
Inline SVG elements are indented like HTML, but self-closing SVG tags such as <path ... /> are treated as open containers, so the indentation drifts right after each one.
Can I choose tabs or four-space indentation?
No. The formatter always uses two spaces per level. Most code editors can convert the indentation after you paste the result.

Explore the category

Glossary

Indentation
The use of leading spaces or tabs before each line of code to visually represent the nesting depth of each element in the document tree.
Void Element
An HTML element that cannot have child nodes and therefore has no closing tag — including <br>, <hr>, <img>, <input>, <link>, and <meta>.
DOM Tree
The browser's in-memory representation of an HTML document as a hierarchy of nodes. The formatter's indentation mirrors this tree structure visually.
Attribute Order
The sequence in which attributes appear on an HTML opening tag. While order has no semantic effect, consistent ordering aids readability and reduces noisy diffs.
EditorConfig
A project-level configuration file (.editorconfig) that standardises formatting settings like indent style and size across different editors and IDEs.
Pretty-Printing
The general technique of reformatting source code with consistent indentation, line breaks, and spacing to improve human readability without changing program behaviour.
A LITTLE HELP. A LOT DONE.
Good tools.
Great flow.

Your shortcut to the everyday. Create, convert, calculate,
and get back to what you love.

✓ Free to use✓ No sign-up✓ 500+ possibilities