HTML Minifier & Beautifier

Minify HTML to make your pages smaller and faster, or beautify messy HTML so it is easy to read and edit. See exactly how many bytes you save, then copy or download the result.

  • 100% free
  • No sign-up
  • Runs in your browser

Paste your HTML

Minify options
Whitespace
Beautify options
Indent
Wrap long lines

Updates as you type. Text in <pre> and <textarea> and attribute values are never changed. If your layout relies on gaps between inline-block items, choose Keep one space.

Result

Your minified or beautified HTML and the size saved will appear here. Paste some HTML or try the example.

About the tool

How the HTML Minifier & Beautifier works

The HTML Minifier & Beautifier turns your markup into whichever form you need. Paste HTML or drop an .html file, then press Minify to get a smaller page for your website, or Beautify to turn a squashed, one-line page into neatly indented code you can read and edit. The result updates as you type and shows the size before and after, so you can see exactly how many bytes you saved.

Minifying removes comments and the whitespace that browsers ignore, such as the line breaks and indentation between block elements like div, p and li, while keeping a single space where text and inline elements need it. Text inside pre and textarea, and every attribute value, is left exactly as written. It also drops default attributes such as type="text/javascript", and it can minify inline style and script blocks with the same engines as our CSS and JS minifiers. Conditional comments and comments that start with <!--! are kept unless you turn that off. If your layout relies on the gaps between inline-block items, choose Keep one space.

Beautifying uses the open-source js-beautify library to put each block element on its own line, indented with 2 spaces, 4 spaces or tabs, while short inline content such as links and bold text stays on one readable line. Inline CSS and JavaScript can be formatted too. The tool also warns you about tags that are never closed, closing tags with no match and unfinished comments, with the line number. Everything runs in your browser, so your HTML never leaves your device. It does not use AI.

Frequently asked questions

Is my HTML uploaded anywhere?

No. Minifying and beautifying happen in your browser on your own device. The formatting libraries are downloaded from this site the first time you need them, and your HTML is never sent to a server, so it is safe to use with private or unreleased pages.

Can minifying change how my page looks?

It is designed not to. Smart mode only removes whitespace that browsers do not show, such as spaces between block elements like div, p and li, and it keeps one space between inline elements. The one thing it cannot know is your CSS: if you have made li, div or similar elements display inline-block, the space between them is visible, so choose Keep one space instead. Content in pre and textarea is never changed.

Does it minify inline CSS and JavaScript?

Yes, if Minify inline CSS and JavaScript is ticked. Style blocks are minified with the same engine as our CSS Minifier, script blocks with Terser, and JSON-LD is compacted. Scripts of other types, such as templates, are left alone. If a block has a syntax error, it is kept exactly as written and you see a warning with the line number.

Which comments are kept?

All normal comments are removed when you minify. Conditional comments such as <!--[if IE]> and comments that start with <!--! (often used for licences) are kept by default, because removing them can change behaviour or break a licence. Untick the option to remove those too, or untick Remove comments to keep every comment.

How much smaller will my HTML get?

It depends on how the page is written. Hand-written HTML with indentation and comments usually shrinks by 10 to 25 percent, and more if it has large inline styles and scripts. Pages that are mostly attributes and inline SVG shrink less. Your web server's gzip or Brotli compression then makes the download smaller still.

Does it fix broken HTML?

No. It reformats your HTML without repairing it, but it does warn you about common mistakes: tags that are never closed, closing tags with no matching opening tag, unfinished comments and attribute values with a missing quote. Each warning shows the line number so you can fix it in your source. Tags that HTML lets you leave open, such as li and p, are not reported.

Keep exploring
  • Free
    Developer

    Word to HTML Converter

    Turn Word documents (.docx) or text pasted from Word into clean HTML or Markdown for any website, CMS or email.

    • DOCX to HTML
    • Markdown
    • Paste from Word
  • Free
    Developer

    JSON Formatter & Validator

    Format, validate and minify JSON, find errors by line, fix common mistakes, browse a tree view or convert to CSV.

    • Beautify
    • Validate
    • JSON to CSV
  • Free
    Developer

    Base64 & URL Encoder / Decoder

    Encode and decode Base64 text and files, turn images into data URIs, and encode, decode or parse URLs.

    • Base64
    • Data URI
    • URL decode
For makers

Have an AI Tool?

Submit your AI tool and help others discover it.