HTML Formatter

138 → 159 chars (15% larger)

About HTML Formatter

Paste HTML and either beautify it into readable, consistently indented markup, or minify it by stripping comments and collapsing whitespace. Runs entirely in your browser, so markup from a private project never has to leave your machine.

Minified or inconsistently-indented HTML is hard to read and easy to misjudge — is that closing div actually where you think it is? Beautifying restores a consistent, readable indentation so the real nesting is obvious at a glance, which is usually the fastest way to spot a missing or misplaced tag.

Minifying goes the other direction for shipping: stripping comments and collapsing runs of whitespace down to a single space trims real bytes without changing how the page renders — whitespace inside normal flow already collapses to one space in a browser, so nothing here removes visible spacing, only the redundant copies of it.

Both directions are careful about the handful of elements where whitespace actually matters: `<script>`, `<style>`, `<pre>` and `<textarea>` content is always left completely untouched, never reformatted or collapsed, since doing either could silently change what a script does or how preformatted text displays.

What you can use it for

  • Make a minified or badly-indented HTML file readable again to debug a layout issue.
  • Check that tags are nested the way you expect before it turns into a bigger bug.
  • Shrink an HTML snippet's size before shipping it, without a build step.
  • Clean up markup copied from a CMS export or another site's page source.
  • Standardize indentation across a team without configuring a build-time formatter.

How it works, step by step

  1. 1

    Paste HTML

    Any snippet or full document.

  2. 2

    Choose Format or Minify

    Format also lets you pick 2 spaces, 4 spaces, or a tab.

  3. 3

    Copy the result

    Script, style, pre and textarea content is always left untouched.

Frequently asked questions

Does minifying ever change how the page looks?

No — it only strips comments and collapses whitespace to a single space outside script/style/pre/textarea content, and a browser already collapses runs of whitespace to one space in normal page flow. Nothing about visible spacing or rendering changes.

Will this touch the JavaScript inside a <script> tag or CSS inside <style>?

No — content inside script, style, pre and textarea elements is always copied through exactly as written, in both Format and Minify, since whitespace there can be meaningful (a line comment, preformatted text) rather than purely cosmetic.

Does this fix broken or invalid HTML?

No — it formats or minifies the structure it's given; it doesn't validate, auto-close mismatched tags, or otherwise correct invalid markup.

Is my HTML uploaded anywhere?

No. Formatting and minifying both happen entirely in your browser.