Code Minifier · Tutorial
How to minify an HTML landing page
5 min readbeginnerUpdated
Single-file landing pages often carry indentation, comments and inline code. You will minify one so the HTML, its style tag and its script all shrink, without changing how the page looks.
What you need
- The Code Minifier
- An HTML page, or the example sale page
Steps
Open the page
Drop your .html file on the page or load the example: a sale page with a comment, a style tag, a disabled button and an inline script.
Review the default options
With Remove comments and Minify inline CSS and JS on, comments disappear, the CSS is shortened (
#ff0000becomesred) and the script is compressed.Check the details
The
typeattributes on style and script are gone,disabled="disabled"is now justdisabledand the heading's extra spaces are trimmed.<button type="button" disabled>Coming soon</button>Try aggressive mode
Turn on Drop optional tags and quotes to remove
<html>,<head>and<body>and unneeded quotes. Use it only for files you won't edit by hand.
Try it yourself
Opens the Code Minifier with this tutorial's sample loaded.
Common mistakes
- Minifying templates with server tags
- Template syntax such as PHP tags or placeholders may be changed. Minify the final HTML instead.
- Removing comments that tools rely on
- Some systems use comments as markers. Turn off Remove comments for those pages.
- Editing the minified file
- Keep your readable source and minify a copy each time you publish.
Next steps
Go back to the Code Minifier, or keep going with one of these: