PublicSoftTools
Tools16 min read·PublicSoftTools Team·May 2026

Code Minifier — Minify JavaScript, CSS, and HTML

Minification reduces the file size of JavaScript, CSS, and HTML by removing whitespace, comments, and unnecessary characters without changing the code's functionality. Smaller files load faster — and page speed is a ranking factor, affects conversion rates, and directly impacts user experience, especially on mobile networks. The free code minifier on PublicSoftTools minifies JS, CSS, and HTML instantly in your browser.

How to Minify Code

  1. Open the code minifier.
  2. Select the code type: JavaScript, CSS, or HTML.
  3. Paste your code into the input panel.
  4. Click Minify. The minified output appears in the right panel.
  5. The tool shows the original size, minified size, and percentage reduction.
  6. Copy the minified output. Use this in your production build in place of the original file.

Minification Techniques

TechniqueApplies toSize reductionWhat it does
Whitespace removalJS, CSS, HTML10–30%Removes all unnecessary spaces, tabs, and newlines. Keeps only whitespace that is part of string literals.
Comment removalJS, CSS, HTML5–20%Removes all // line comments, /* */ block comments, and <!-- --> HTML comments. Does not remove conditional comments (IE).
Variable name shortening (mangling)JS only10–25%Renames local variables and function parameters to single or double characters (a, b, c, aa). Only applies to local scope — public API names preserved.
Dead code eliminationJS (advanced)5–30%Removes code that can never be executed: unreachable code after return, code inside if (false) {}. Also removes unused functions when tree-shaking is applied.
Property shorthandCSS5–15%Converts multi-property declarations to shorthand: margin-top: 0; margin-right: 0; margin-bottom: 0; margin-left: 0; → margin: 0
Attribute value quotingHTML2–5%Removes unnecessary quotes from HTML attributes where the value does not contain spaces: class="foo" → class=foo (in some contexts).
Constant foldingJS (advanced)1–5%Evaluates constant expressions at minification time: 60 * 60 * 24 → 86400; "Hello" + " " + "World" → "Hello World".

File Size Impact of Minification

File typeTypical unminifiedAfter minificationAfter minify + gzipTools
JavaScript (unminified)50–500 KB20–250 KB10–80 KBTerser, UglifyJS, esbuild
CSS (unminified)20–100 KB15–70 KB5–25 KBcssnano, CleanCSS
HTML page10–100 KB8–80 KB3–30 KBhtml-minifier, HTMLMinifier-terser
React bundle (unoptimised)2–5 MB500 KB–2 MB100–400 KBWebpack + Terser; Vite + esbuild

Why Minification Matters for Performance

Page load speed is directly linked to file size — every byte must be downloaded before it can be executed. Key impacts:

Minification vs. Compression (Gzip/Brotli)

Minification and compression (gzip or Brotli) are complementary — both should be applied:

Minification complements compression because repeated patterns in minified code (short variable names, consistent structure) compress better than varied whitespace and comments. Minify first, then let your web server apply gzip on top — you typically get 60–80% total reduction from unminified to minified-and-compressed.

Minification in Build Pipelines

For production projects, minification is typically handled automatically by build tools:

The online code minifier is useful for one-off files, testing minification output, understanding what minification does, or for projects without a build pipeline.

Source Maps: Debugging Minified Code

Minified code is unreadable — variable names are single characters, all on one line. Source maps solve the debugging problem: they are separate files (.map) that map the minified output back to the original source code. When your browser devtools encounter an error in minified production code, they use the source map to show you the original file and line number.

Source maps should be generated by your build tool but not served to end users (they reveal your source code). Options:

Common Minification Pitfalls

Common Questions

Does minification change what the code does?

Correct minification should not change the code's behaviour. The output is functionally identical — it produces the same results for all valid inputs. The only differences are: variable names (mangled to shorter forms within local scope), formatting (no whitespace/newlines), and comments (removed). If minified code behaves differently from the original, it indicates a bug in the minifier or a code pattern the minifier does not handle correctly (rare, but more common with aggressive optimisations like dead code elimination).

Should I commit minified code to version control?

Generally no. Minified code creates very large, unreadable diffs that make code review impossible. The conventional approach: commit unminified source code, and produce minified output as part of the build process (e.g., npm run build). The build output (/dist, /build) is typically added to .gitignore. For deployed static sites or libraries where you publish to npm/CDN, the minified file is included in the published package but not necessarily in the repository.

What is the difference between minification and obfuscation?

Minification optimises for smaller file size — it makes code unreadable as a side effect, but that is not the goal. Obfuscation deliberately makes code difficult to understand and reverse-engineer — through variable name randomisation, control flow flattening, string encryption, and other anti-analysis techniques. Obfuscated code is harder to decompile but often larger and slower than minified code. Minification is standard web practice; obfuscation is niche (mainly for commercial software protection). Neither provides true security — determined developers can reverse engineer either.

Minify Your Code

Paste JavaScript, CSS, or HTML and get instant minified output with before/after size comparison. Free, no signup.

Open Code Minifier