H
Runs in your browserNothing is uploadedDeveloper

HTML Formatter

Indent messy HTML so its structure is clear, or minify it by removing extra whitespace. Pre, script and style blocks are kept intact.

Loading tool…
Short answer

HTML Formatter indents HTML so its nesting is easy to follow, or minifies it by collapsing whitespace. Inline tags such as links and bold text stay in their sentence, and pre, textarea, script and style blocks are handled carefully.

What does an HTML formatter do?

Beautify

Each block element, such as a div, a paragraph or a list item, starts on its own line, indented by its depth. Short elements stay on one line. Content of pre and textarea is copied exactly because there whitespace is visible.

Minify

Runs of whitespace become a single space and whitespace next to block tags is removed. One space is kept between inline elements, because removing it would join words on the page.

Why use HTML Formatter?

  • Read generated markup. Turn one long line of HTML from a CMS or an email builder into something you can read and edit.
  • Smaller pages. Minify templates and email HTML without breaking the text spacing.
  • Nothing runs. The HTML is processed as text and never rendered, so scripts in it cannot run.

How to use HTML Formatter, step by step

HTML Formatter in PrintxPDF with a file loaded, options on the right and the run button below
HTML Formatter with a file loaded: the steps below follow this screen.
  1. Paste your HTML into HTML Formatter. A whole page or a fragment.
  2. Choose Beautify or Minify. For minify, choose whether to keep comments.
  3. Copy or download the result. It updates as you type.

Frequently asked questions

Does it fix broken HTML?

No. It lays out the tags you gave it. Unclosed tags are kept as they are, which can make the indent drift and is a hint where the mistake is.

Are inline scripts and styles reformatted?

Their content is re-indented as a block but not rewritten. Use the CSS Formatter for style rules.

Is minified HTML still valid?

Yes. Only whitespace that does not render is removed, and attribute values are left alone.

Looking for the long version? The guides cover each of these jobs in depth.