HTML Formatter, Minifier & Beautifier Online

Paste HTML, format it for readability, or minify it for production without uploading your code. You can also open a local file, inspect parsing feedback, and preview the result safely.

HTML formatter and minifier tool

Mode and editor settings
Indentation
Line wrapping
Embedded code
Editor and storage

1. Input HTML

Paste, type, choose a local .html/.htm file, or drop one onto the editor. Press Ctrl/Cmd+Enter to run the selected mode.

1 line · 0 characters · 0 B Line 1, column 1
No file selected. Drop a local .html or .htm file here.
Parsing feedback will appear as you type.
Loading engines…

3. Output HTML

Review the processed result before using it in production. Output is not autosaved.

1 line · 0 characters · 0 B No output yet

Ready. Add HTML and choose a mode.

Safe rendered preview (off by default)

Advertisement

How to format or minify HTML

  1. Add HTMLPaste HTML into the input editor, load the sample, or choose a local .html or .htm file.
  2. Choose a modeSelect Format / Beautify or Minify, then review the settings for that mode.
  3. Process the HTMLSelect Format HTML or Minify HTML and review any parsing feedback without assuming the tool repaired malformed markup.
  4. Use the resultReview the output and optional sandboxed preview, then copy or download the processed HTML.

HTML minification and formatting example

This sample includes nested and inline elements, a removable comment, preformatted text, CSS, and JavaScript. Byte totals use UTF-8 bytes and are calculated from the exact snippets shown.

Input

<!doctype html>
<html><head><style>body { color: #222; }</style></head>
<body>
  <main><h1>Hello <em>world</em></h1>
    <!-- remove in minified output -->
    <p>Inline <strong>spacing</strong> matters.</p>
    <pre>keep   these
spaces</pre></main>
  <script>const greet = () => console.log('hello');</script>
</body></html>

Formatted result

<!doctype html>
<html>
  <head>
    <style>
      body { color: #222; }
    </style>
  </head>
  <body>
    <main>
      <h1>Hello <em>world</em></h1>
      <!-- remove in minified output -->
      <p>Inline <strong>spacing</strong> matters.</p>
      <pre>keep   these
spaces</pre>
    </main>
    <script>
      const greet = () => console.log('hello');
    </script>
  </body>
</html>

Minified result

<!doctype html><html><head><style>body{color:#222}</style></head><body><main><h1>Hello <em>world</em></h1><p>Inline <strong>spacing</strong> matters.</p><pre>keep   these
spaces</pre></main><script>const greet=()=>console.log("hello");</script></body></html>

Practical HTML formatting and minification guide

How formatting works

The formatter tokenizes markup and applies consistent indentation, line breaks, wrapping, and optional embedded-code formatting. It improves readability; it does not make invalid HTML valid or recover the author's original layout.

How minification works

The minifier parses HTML and applies only the enabled transformations. Conservative mode retains optional syntax and attribute quotes. Maximum mode enables more HTML5-aware reductions and embedded CSS/JavaScript processing, so it needs broader testing.

What the options change

Indentation and wrapping affect readable output. Minification switches control comments, collapsible whitespace, optional tags, quotes, default attributes, boolean syntax, attribute order, and embedded CSS/JavaScript. Each interface option explains its own tradeoff.

What is preserved

Text content, doctypes, tag structure, and attribute values are retained unless a selected minification rule explicitly permits a change. pre and textarea content is treated as preformatted. Conditional comments and common template fragments are protected when their options apply.

When to format or minify

Format HTML before reading, reviewing, debugging, or editing it. Minify a tested copy for delivery to browsers. Keep the readable source separately; minified output is a build artifact, not a replacement for source control.

When a build-pipeline minifier is better

Use a project build pipeline when output must be reproducible, tested automatically, source-mapped, processed in batches, or integrated with framework compilation. This browser tool is best for inspection, experiments, one-off files, and comparing settings.

Engines, safety limits, and testing

Processing engines: minification uses html-minifier-terser 7.2.0; formatting uses js-beautify 2.0.3; feedback uses HTMLHint 1.9.2; and the enhanced editor uses CodeMirror 5.65.21. These pinned libraries download from jsDelivr or cdnjs, then transformations run locally.

Important limits: whitespace can be meaningful around inline elements. Minification is not validation. Beautification cannot reconstruct removed comments or original formatting. Malformed markup may be rejected or produce unexpected output. Retest email templates, framework syntax, and any production-critical result.

  • script and style: contents are preserved unless embedded formatting or minification is enabled.
  • pre and textarea: preformatted contents are preserved by the processing engines.
  • code: the formatter keeps its content unformatted, but a standalone code element still follows normal HTML whitespace rules during minification; wrap whitespace-sensitive code in pre.
  • SVG: parsed as markup with case-sensitive names preserved; Maximum options may still optimize legal attribute syntax.
  • Conditional comments: kept while Protect conditional comments is enabled; disabling it can remove them with other comments.
  • Template fragments: common {{...}}, {%...%}, <%...%>, and [[...]] fragments are protected during minification. Framework-specific syntax can differ and must be tested.

The preview has an empty iframe sandbox and an injected Content Security Policy. It disables scripts, forms, navigation, frames, and external network resources; only inline styles and data/blob media are allowed. It is a visual aid, not a security scanner or full browser-equivalence test.

HTML formatter and minifier FAQ

What is the difference between an HTML formatter, beautifier, and minifier?

Formatter and beautifier usually mean the same thing: they add consistent indentation and line breaks for people to read. A minifier removes safe-to-remove bytes for delivery. Formatting generally increases size; minification generally reduces it.

Does the tool process inline CSS and JavaScript?

Only when you enable the embedded CSS and JavaScript option for the selected mode. Leave it off to keep script and style contents unchanged as far as that engine permits. Always test generated code.

Is HTML minification reversible?

No. A formatter can make minified markup readable, but it cannot reconstruct removed comments, optional tags, attribute quotes, or the author's original spacing and line breaks. Keep the source file in version control.

Can removing whitespace break a page?

Yes. Whitespace can be meaningful between inline elements, in preformatted content, in templates, and in some email layouts. Conservative mode reduces risk but does not remove the need to test the output.

What happens with malformed HTML?

HTMLHint reports likely problems with line and column locations, and the processing engines may reject or reinterpret malformed input. The tool does not claim to repair markup automatically.

Does it support HTML5, SVG, and template syntax?

The engines handle common HTML5 and inline SVG markup. Common Mustache, Liquid, ERB, and double-bracket template fragments are protected during minification, but framework syntax varies and must be retested. SVG case is preserved.

What is the maximum practical file size?

There is no upload limit because processing is local. Performance depends on the device and browser; files above 2 MB trigger a warning, and about 5 MB is a sensible practical ceiling for this interactive page.

Which indentation choices are available?

Formatting supports tabs or one to eight spaces per indentation level, optional line wrapping, and a configurable maximum line length from 40 to 500 characters.

Is my HTML private?

Transformations run in the browser and this page does not transmit editor contents. Pinned processing and editor libraries are downloaded from jsDelivr and cdnjs, so those providers can receive ordinary page-resource request data, but not the HTML in the editor.

Does the tool save my HTML locally?

Autosave is on by default and stores input in this browser's localStorage. You can turn autosave off or select Clear saved input. Output is not autosaved.

Is it safe for HTML email templates?

Use Conservative mode and test every output in the email clients you support. Email layouts often depend on whitespace, conditional comments, table structure, and unusual attributes, so Maximum mode is not recommended without a full rendering test.

Does validation guarantee valid HTML?

No. Parsing feedback is a useful lint check, not a standards-conformance guarantee, and minification is not validation. Use a dedicated validator and test the rendered result for production-critical markup.

Explore more tools