ZapKit

HTML Beautifier & Minifier

Make minified or messy HTML readable with consistent indentation, or shrink it for production by stripping comments and whitespace.

What is an HTML beautifier?

An HTML beautifier reformats HTML so nested elements are indented and easy to follow, which helps when reading the source of a minified page, an email template or code generated by a CMS. A minifier does the opposite, removing what browsers don't need so pages download faster.

This tool does both. Beautifying lets you choose two spaces, four spaces or tabs; minifying reports the size before and after. Preformatted text, text areas and scripts are protected, so the minified page looks exactly like the original.

How to use the HTML Beautifier

  1. 1.Paste HTML

    A whole page, a template or a snippet.

  2. 2.Beautify or minify

    Choose indentation for beautifying; minifying needs no options.

  3. 3.Copy or download

    Minify shows the bytes saved.

Example: a one-line page

The sample page is on a single line. Beautified with 2 spaces:

Before
1 line
After
26 lines, one element per line
<style>
kept inside <head>, indented
Comment <!-- main -->
kept when beautifying, removed when minifying

Beautifying grows the 239-byte page to 326 bytes of indentation and line breaks; minifying the result brings it back to 242.

What each mode changes

Beautify uses js-beautify to put each block element on its own line and indent nested tags, keeping inline elements together. Minify removes comments (except Internet Explorer conditional comments), collapses runs of whitespace to a single space and trims spaces inside tags.

Whitespace is never removed entirely between tags, because a space between two inline elements is visible on the page. Content inside <pre> and <textarea> is left untouched, <script> blocks are kept as they are, and <style> blocks are minified as CSS.

Frequently asked questions

Will minifying break my page?

It's designed not to: it only removes comments and redundant whitespace, never markup.

How much does minifying save?

Typically 10–25% on hand-written HTML. Gzip or Brotli compression on the server saves far more.

Does it fix invalid HTML?

No. It re-indents what's there. Use the W3C validator to find errors.

Are scripts minified?

No, they're left as they are. Use the JavaScript minifier for script code.

More Developer tools