Skip to content

HTML Formatter & Minifier - Format or Minify HTML Online

HTML input

Format or minify HTML

Paste a full document or a fragment and choose Format or Minify. Format indents each element by its nesting depth. Void elements such as <br>, <img> and <input> do not expect a closing tag, so they do not throw the indentation off. The contents of <pre>, <textarea>, <script> and <style> are left exactly as they were in both modes.

Minify without breaking spacing

Minify removes comments and collapses runs of whitespace to a single space. It only drops a space entirely when a block-level tag is next to it, because the space in Hello <b>world</b> is visible on the page. <div>\n <p>a b</p>\n</div> becomes <div><p>a b</p></div>.

Limits

The formatter puts every tag on its own line, inline tags included, so <p>Hi <b>there</b></p> is split over several lines. That is fine for reading but can add visible spaces inside inline elements, so check the result before pasting formatted markup back into a page. Attributes are not reordered or re-quoted. To turn markup into React code, use HTML to JSX.

Related Tools

Frequently Asked Questions

How does the indentation work?
Each opening tag adds one level and each closing tag removes one. Void elements such as <br>, <img>, <input> and <hr> do not add a level, so a missing </div> is the usual reason the output drifts to the right.
Are pre, script and style blocks changed?
No. The contents of <pre>, <textarea>, <script> and <style> are copied as they are in both modes, so code samples, inline JavaScript and CSS keep their whitespace.
What happens to comments?
Formatting keeps them. Minifying removes every comment, including old IE conditional comments such as <!--[if IE]>.
Is my HTML sent anywhere?
No. Both modes run in your browser.