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

Steps

  1. 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.

  2. Review the default options

    With Remove comments and Minify inline CSS and JS on, comments disappear, the CSS is shortened (#ff0000 becomes red) and the script is compressed.

  3. Check the details

    The type attributes on style and script are gone, disabled="disabled" is now just disabled and the heading's extra spaces are trimmed.

    <button type="button" disabled>Coming soon</button>
  4. 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.

Try it now

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: