← All blog posts

HTML Minifier for beginners — start here

WhiteUI · A plain-English guide to the HTML Minifier

If you have just written your first web page, you have probably noticed that the file looks nothing like the page in the browser: it is full of line breaks, indentation and notes to yourself, while the browser shows only the words and the layout. The HTML Minifier takes the file you wrote and returns the same page with all that extra space taken out. This guide starts from zero, explains what minifying is, and ends with two tries you can check yourself.

At a glance

Your first try: 30% smaller27 bytes removed64 bytes kept91 bytes in, 64 bytes out
The sample page goes from 91 bytes to 64 bytes. The 27 bytes removed are the comment, the line breaks, and the spaces around Hello.

What minifying is

Minifying means removing the parts of a file that are there for the person who wrote it, not for the browser that reads it. A browser does not need line breaks or indentation to understand a page, and it ignores comments entirely, so all of those can go. What stays is everything the browser needs: the tags, the attributes, the class names, and the words themselves, with one space between them. A minified page looks like one long line of code, which is hard for a person to read, but the browser does not mind at all.

Why a smaller file matters

Every byte of a page has to travel from the server to the visitor’s phone or computer, so a smaller file arrives sooner and uses less data. On a fast connection the difference is small, but on a slow mobile connection it is real, and it applies to every single visit. The sample page goes from 91 bytes to 64 bytes, which is 27 bytes saved, or 30% smaller. A whole page of 1,744 bytes, such as a shop page with twenty products, comes down to 1,415 bytes, which is 329 bytes saved, or 19% smaller. The saving is modest for one page, but it repeats on every visit, for every visitor.

Your first try: leave everything as it is

Open the tool and look before you touch anything. A sample page is already loaded: a card with a heading that reads Hello, a comment that says a note, and a paragraph that reads Welcome to WhiteUI. The result already says 30% smaller, with Original: 91 characters, Minified: 64 characters, and Saved: 27 characters. Press Copy minified HTML and paste the result somewhere to see what a minified page looks like: one line, no gaps, same words.

Your second try: paste a page of your own

Now click into the Your HTML box, select the sample, and paste in a page you wrote yourself. The tool minifies as you type, so the numbers change at once. A typical small page with a heading, a paragraph and a list is 291 bytes as written and 198 bytes minified, with 93 bytes saved, or 32% smaller. If your page saves less than that, do not worry: a page that is already written tightly has less to remove, and a page with a long comment or deep indentation saves more.

What minifying never touches

Three things are always safe. The words on your page keep their single spaces, so a sentence reads exactly as before. Attribute values are copied exactly, so class="card" stays class="card" and a link to /about/ still points to /about/. And special codes such as   are left alone: a paragraph with two   codes in it is 29 bytes before minifying and 29 bytes after, because the tool only touches real whitespace, not the codes that stand for it.

The common mistake

Beginners often minify their only copy of a page and then try to edit the minified version, which is one long line with no gaps. Do not do that. Keep the original file with its line breaks and indentation, because that is the version a person can read and fix, and minify a copy whenever you publish. The minified file is for the browser; the original file is for you.

Frequently asked questions

What is an HTML minifier?

A tool that removes the parts of an HTML file a browser does not need, such as line breaks, indentation and comments, while keeping the tags, attributes and words exactly as they are.

Why should a smaller HTML file matter?

Every byte has to travel to the visitor, so a smaller file arrives sooner and uses less data, on every visit, for every visitor.

What does the sample page save?

It goes from 91 bytes to 64 bytes, saving 27 bytes, or 30% smaller.

Should I edit the minified file afterwards?

No. Keep your original file with its line breaks and indentation for editing, and minify a copy whenever you publish.

More guides on the HTML Minifier

Try it yourself

Try the HTML Minifier — free, in your browser.

Open the HTML Minifier