Minifying code means removing what the browser doesn't need to run it: spaces, line breaks and comments. The code minifier on this site does this for HTML, CSS or JavaScript in your browser and shows the percentage of characters it removed.
A well-formatted file, with indentation and explanatory comments, is comfortable to develop and maintain. That same format adds bytes the browser doesn't use when running the code. Minifying removes them without changing what the program does.
What minification actually does
The minifier only strips comments and unnecessary whitespace. It doesn't rename variables, shorten colour values or change the logic. Given this CSS:
/* Cabecera de la web */
body {
margin: 0;
color: #333333;
}
the tool returns:
body{margin:0;color:#333333}
Comments that start with /*!, such as license notices, are kept. In HTML, comments are removed and whitespace between tags is reduced, but the content of pre, textarea, script and style is left untouched, and conditional comments are kept. In JavaScript the output is basic: it strips comments and whitespace, without renaming variables. For production, the tool itself recommends using a bundler.
How to minify your code
- Paste your code into the CSS, HTML or JS tab that matches it.
- The tool removes comments and unnecessary whitespace.
- Copy the result, or download it as a file.
Why this still matters in the broadband era
With fast connections, a few kilobytes look irrelevant. File weight still matters in two cases: when the same file is downloaded by every visitor, and when the connection is slow or unstable, as on many mobile devices. In those cases every byte that doesn't travel is saved on every download. For SVG images, the SVG optimizer reduces the weight of icons, and there's a guide on it.
The right workflow: develop unminified, publish minified
Minifying isn't something you do while writing code: the source, with comments and readable indentation, should stay as the working version. Minification is the last step, applied when you generate the version users actually receive. Minifying the working code directly, without keeping the readable original, makes it much harder to maintain and debug.
Common use cases
- Reducing CSS and JS weight before pushing to production in projects without an automated build step.
- Preparing code to embed somewhere with limited space, where every byte counts.
- Understanding a minified script you found online: first run it through a code formatter to make it readable again, then minify it with your changes.
Frequently asked questions
Does minifying break the code? Removing comments and whitespace shouldn't change what it does. Even so, the JavaScript minifier is basic and can fail in edge cases, so always test the minified version before publishing it.
Can I minify HTML the same way as CSS or JS? Yes, with the HTML tab. If you later need to read minified HTML again, the HTML formatter re-indents it.
How much smaller is the result? It depends on the code. The tool shows the percentage of characters removed after each conversion.
Should I minify my source code directly? No. Keep the readable code as the source of truth and minify only the version you publish.
Is my code uploaded to a server? No. The whole process runs in your browser.
Minify your HTML, CSS or JavaScript with the code minifier, 100% in your browser.