HTML Formatter

Indent and format minified or poorly structured HTML into clean, readable markup.

Runs locallyInstantPrivate
Input
Output
Formatted HTML appears here.

What This Tool Does

Paste any HTML — minified in a single line, exported from a tool, or scrambled by copy-paste — and the formatter rebuilds it with consistent indentation and line breaks. Block elements like <div>, <p>, and <header> each get their own line. Inline elements like <a>, <strong>, and <span> stay on the same line as their surrounding text. Void elements (<br>, <img>, <meta>) are placed correctly without a closing tag.

How to Use

  1. Paste your HTML into the input box on the left.
  2. Choose your preferred indentation: 2 spaces, 4 spaces, or tabs.
  3. The formatted output appears instantly on the right.
  4. Click Copy to copy the result to your clipboard.

When You Need It

  • Reading minified HTML downloaded from a live site (see also: HTML Minifier to go the other direction)
  • Cleaning up HTML generated by a rich text editor or CMS
  • Reviewing templated HTML from a framework before editing
  • Making a colleague's markup readable for a code review
  • Preparing HTML snippets for documentation or a blog post (strip tags first with the HTML Stripper if you need plain text)

Frequently Asked Questions

Does it validate my HTML?

No. The formatter only adjusts whitespace and indentation — it does not check whether your HTML is well-formed, fix unclosed tags, or report errors. Use the browser DevTools or an HTML validator for structural checking.

Will it change the content or attributes of my tags?

No. Only whitespace between tokens is modified. Tag names, attribute names, attribute values, and text content are preserved exactly as they appear in the input.

How does it handle inline elements?

Inline elements (<a>, <strong>, <em>, <span>, and others) are kept on the same line as the surrounding text or tags. Block-level ancestors still get their own indented line.

Does it handle HTML comments and DOCTYPE?

Yes. Comments (<!-- … -->) and the <!DOCTYPE html> declaration are placed on their own lines at the correct indentation level.

Is my HTML sent to a server?

No. All formatting runs in JavaScript in your browser. Your markup never leaves your device.

Related tools