HTML Minifier for students — with examples
School and college web work often asks for a page that loads fast and a write-up that shows your working: a project site, a class homepage, or a portfolio page for an assignment. The HTML Minifier does the minifying in seconds, and the examples below use the same numbers your coursework will, so you can check your own results against them and quote the exact figures in your write-up.
At a glance
Example 1: a class homepage, 291 bytes to 198
A class homepage usually has a doctype, a head with a title, and a body with a heading, a paragraph and a list. One such page, with a comment that reads page title in the head, is 291 bytes as written. Minified it is 198 bytes, so 93 bytes are saved, or 32% smaller. The comment, which is 19 characters on its own, disappears. The heading <h1> Hello world </h1> becomes <h1>Hello world</h1>, with the words still separated by one space, so it reads the same. Every line break and every indent between tags is gone, and the whole page sits on one line. Quote those three numbers in your write-up: 291, 198 and 93.
Example 2: a navigation list, 147 bytes to 125
A navigation list is a good second example because it is mostly tags and links, so there is less dead weight to find. A nav with three links, Home, About and Contact, is 147 bytes as written and 125 bytes minified, so 22 bytes are saved, or 15% smaller. The links themselves, including the slash in each href, are copied exactly. This example is useful in coursework because it shows that the percentage depends on how much whitespace the original had, not on how big the page is: a page that was already written tightly saves a smaller percentage, and that is correct, not a fault.
Example 3: a paragraph with doubled spaces, 49 bytes to 35
A short example is handy when you need to show the rule in action. The line <p>Hello world, this is a test.</p> is 49 bytes, and minified it reads <p>Hello world, this is a test.</p>, which is 35 bytes, so 14 bytes are saved, or 29% smaller. Every run of spaces collapses to one space, and the words still have exactly one space between them.
Checking your work with the percentage
The percentage is (original − minified) ÷ original × 100, rounded to a whole number. For the homepage that is 93 ÷ 291 × 100, which is 32.0%, shown as 32%. For the navigation list it is 22 ÷ 147 × 100, which is 15.0%, shown as 15%. For the paragraph it is 14 ÷ 49 × 100, which is 28.6%, shown as 29%. Work one of those sums out by hand and compare it with the big line on the tool: if they match, your result is right, and you have a checked figure for your assignment.
What to write in your notes
Write down the five rules: comments removed, whitespace runs collapsed to one space, space between tags removed, space after and before tags removed, ends trimmed. Then write down the three numbers for each example you tried: the original size, the minified size, and the bytes saved.
The common mistake
Students sometimes minify a page that has a pre block holding code, and hand in a result where the code has lost its indentation. A 61-byte pre block comes out as one line of 49 bytes, with the line breaks gone, and a teacher reading it will mark the code as broken. Check pre blocks before you hand anything in, and if your page has one, minify the rest of the page and leave the pre block out, or say in your write-up that the pre block was left unminified on purpose.
Frequently asked questions
What example should I use for a class homepage?
A 291-byte page with a heading, a paragraph and a list, which minifies to 198 bytes, saving 93 bytes, or 32% smaller.
Why did my navigation list only save 15%?
Because it had only 22 bytes of removable space in 147 bytes. Pages that are mostly markup save a smaller percentage than pages with long comments or deep indentation.
How do I check my percentage by hand?
As (original − minified) ÷ original × 100. For the homepage that is 93 ÷ 291 × 100, which is 32.0%, shown as 32%.
What happens to a pre block in my code?
It loses its indentation and line breaks: a 61-byte pre block comes out as one line of 49 bytes, so check pre blocks before you hand anything in.
More guides on the HTML Minifier
- How to use the HTML Minifier — step by step
- HTML Minifier explained with worked examples
- HTML Minifier formula — how it actually works
- HTML Minifier for beginners — start here
- Common mistakes people make with the HTML Minifier
- HTML Minifier vs doing it by hand — which is faster?
- HTML Minifier — The Complete Guide
- How to get an accurate result from the HTML Minifier
- HTML Minifier for homeowners and DIYers
Try the HTML Minifier — free, in your browser.