HTML Formatter

Indent and beautify HTML with clean nesting while preserving pre and script blocks.

The HTML Formatter takes messy or minified markup and lays it out with clear, consistent indentation so the nesting of your elements becomes obvious at a glance. Each tag sits on its own line, indented according to how deeply it is nested, which turns an unreadable single line of HTML into a structured tree you can actually follow.

It is built for front-end developers cleaning up generated markup, content editors inspecting exported HTML, and anyone debugging a layout who needs to see where a container opens and closes. When elements are properly indented, mismatched or missing closing tags and unexpectedly deep nesting stand out immediately instead of hiding inside a dense block.

Everything runs locally in your browser using JavaScript, so the HTML you paste is never uploaded, logged or stored. That keeps unpublished pages, internal templates and any markup containing private data entirely on your own device while you format it.

Features

  • Indents nested elements so the document structure reads as a clear, hierarchical tree.
  • Preserves the raw contents of pre, textarea, script and style blocks so whitespace-sensitive code stays intact.
  • Recognises void elements like img, br and input so they never add a phantom indentation level.
  • Keeps doctype declarations and comments on their own lines at the correct depth.
  • Collapses insignificant whitespace in text nodes while keeping the visible text on its own line.
  • Offers two-space, four-space or tab indentation to match your project's conventions.
  • Copies the formatted markup or downloads it as a file to drop back into your editor.

How to use HTML Formatter

  1. Paste your HTML, whether minified or inconsistently indented, into the input box.
  2. Choose two spaces, four spaces or a tab for each level of nesting.
  3. Read the formatted markup, with each tag indented to show exactly how the elements nest.
  4. Scan the indentation to spot missing closing tags or elements nested more deeply than expected.
  5. Copy the tidied HTML or download it as a file to use in your project or documentation.

Benefits

  • Developers read and edit generated or minified markup that would otherwise be impenetrable.
  • Debugging layout issues gets easier when the open and close of every container is visible.
  • Content teams inspect exported HTML from a CMS or email tool in a readable form.
  • Consistent indentation keeps templates tidy and diffs meaningful in version control.
  • Whitespace-sensitive pre and script blocks stay byte-for-byte intact during formatting.
  • Because formatting is local, unpublished pages and private markup never leave your device.

HTML nesting carries real meaning, and indentation makes that meaning visible. A list inside a navigation bar inside a header should look progressively indented, and when it does not, you have probably found a stray closing tag or an element that never got closed. Reading formatted markup as a tree is often the fastest way to understand a page you did not write.

Some elements must not be reformatted. The contents of pre and textarea are whitespace-sensitive, and script and style blocks contain code in other languages that should not be re-indented as if it were HTML. The formatter detects these elements and preserves their inner content exactly, indenting only the surrounding tags so your JavaScript, CSS and preformatted text keep working as written.

This formatter uses fast, dependency-free pattern matching rather than a full browser DOM, which keeps it working in any environment and on any fragment of markup. As a result it formats the tags you give it faithfully but does not repair broken HTML; if a closing tag is missing, the indentation will simply reflect that, which is often exactly the clue you need to find the problem.

Frequently asked questions

Related tools