Code Minifier: HTML, CSS & JavaScript

Paste code, press Minify, see exactly how many bytes you save. Strings, regexes and template literals are never touched, and nothing is uploaded.

0 B
Options

Why minify HTML, CSS, and JavaScript?

Comments, indentation, and line breaks make code readable for people, but browsers don't need them, and every byte has to cross the network before a page can render. Stripping them is the simplest size win there is. This minifier does that in your browser and reports the exact savings, raw and gzipped. It reads your code token by token, so it knows what is a string, a comment, a regular expression, or a template literal, never changes the text inside them, and only removes whitespace where the language guarantees it has no effect.

How to minify code

  1. Pick HTML, CSS, or JavaScript. If you paste code that clearly belongs to another tab, the tool switches for you and says so.
  2. Paste your code, drop a file on the box, or tap Upload.
  3. Press Minify (or Ctrl/⌘+Enter) to see the output with its before, after, saved and gzipped sizes. Edits update the result as you type.
  4. Copy the result or Download it as .min.js, .min.css or .min.html, test it where it will run, and keep your original source for future edits.

What is code minification?

Minification removes all unnecessary characters from source code without changing its functionality. This includes whitespace, newlines, comments, and shortening values (like hex colors). Minified code loads faster because there are fewer bytes to download — critical for web performance and Core Web Vitals.

Optimizations by language

HTML

Comments, runs of whitespace, quotes on simple attribute values, default type attributes; inline <script> and <style> minified as JS and CSS

CSS

Comments, whitespace, last semicolons, six-digit hex shorthand, zero units, leading zeros

JavaScript

Comments, indentation, operator spacing, and every line break that doesn't change the meaning

Before and after: one example per language

These small samples were run through this minifier exactly as the tool runs them. Notice the hex color shortened to three digits, the zero that lost its unit, and the quotes dropped from a one-word class name.

HTML

82 → 53 bytes (35% smaller)
<!-- Main navigation -->
<nav class="main">
  <a href="/about">About us</a>
</nav>
<nav class=main> <a href="/about">About us</a> </nav>

CSS

86 → 44 bytes (49% smaller)
/* Primary button */
.button {
  color: #ffffff;
  margin: 0px auto;
  opacity: 0.8;
}
.button{color:#fff;margin:0 auto;opacity:.8}

JavaScript

57 → 30 bytes (47% smaller)
// Add two numbers
function add(a, b) {
  return a + b;
}
function add(a,b){return a+b;}

What minification does, and what it doesn't

Minification rewrites code into a smaller form the browser treats the same way. It is not obfuscation: nothing is encrypted or hidden, and anyone can run minified code through a formatter and read it again, so never rely on it to protect secrets. This tool also doesn't rename variables or remove unused code, which full JavaScript minifiers do to save more space.

It's separate from compression, too. Servers usually send text with gzip or Brotli, which already squeezes repeated whitespace, so the saving after compression is smaller than the percentage shown here, though a minified file still compresses smaller. And keep the readable original: minified code is meant to be generated, not edited. Build tools can also write a source map so dev tools show your original lines while debugging; this tool outputs the minified code only.

What it deliberately leaves alone

The tool splits your code into tokens first, the way a browser does, and only then decides which gaps between them can go. Anywhere a change could alter what the code does, it keeps the byte:

  • Strings, template literals, and regular expressions. "Hello, world = ok" stays exactly as written, and a // inside a string or a URL is never mistaken for a comment.
  • Line breaks JavaScript relies on. Code without semicolons depends on line breaks to end statements, and a break after return or before ++ changes the meaning. Those breaks stay, so semicolon-free code comes out on several lines instead of one.
  • Operators that would fuse. a + +b keeps its space rather than becoming a++b, and the same goes for a - -b and a / /regex/.
  • CSS calc() and selectors. The spaces around + and - in calc(100% - 2px + 1rem) stay, as does the space in div :first-child, which means a first child inside a div. Units on zero are kept inside functions and in flex, where 0 and 0px mean different things.
  • Colors with alpha. Only six-digit colors whose pairs repeat are shortened (#ffffff to #fff); eight-digit colors such as #ffffff80 and ID selectors that look like colors are untouched.
  • Whitespace-sensitive HTML. Everything inside <pre> and <textarea> is kept exactly. Elsewhere a run of whitespace becomes one space rather than nothing, because the space between two inline elements is visible on the page; it is removed outright only where it never renders, such as inside <head> or between table rows.

It handles standard JavaScript, CSS, and HTML, not JSX or other template languages, and it can't see CSS that sets white-space: pre on an ordinary element, so whitespace there is collapsed. For production builds, a full minifier in your build pipeline also renames variables and removes unused code: Terser or esbuild for JavaScript, cssnano or Lightning CSS for stylesheets, and html-minifier-terser for markup.

This tool or a build-step minifier?

A browser minifier is the quick option for a snippet, a single file, an email template or a page you don't build with a bundler. If your project already has a build step, its minifier can go further. What each kind does:

This toolTerser / esbuild (JS)cssnano / Lightning CSS
Removes comments and whitespaceYesYesYes
Renames variablesNoYesNot applicable
Removes unused codeNoYes (dead-code elimination)Merges and drops duplicate rules
Source mapsNoYesYes
SetupNone, works on a phoneNode.js and a configNode.js and a config

Minifying data instead of code? The JSON formatter validates and minifies JSON (and pretty-prints it again), and the YAML validator checks config files. Images are usually the biggest files on a page, so pair this with the image compressor. To compare an original and a changed version of a file line by line, use Text Diff, and to turn a web page's HTML into clean text for notes or an AI prompt, try HTML to Markdown.

Frequently Asked Questions

How do I minify JavaScript online?

Choose the JavaScript tab, paste your code (or upload a .js file) and press Minify, or Ctrl+Enter. The minified code appears below with its before, after and gzip sizes; copy it or download it as a .min.js file. Comments, indentation and every line break that doesn't change the meaning are removed; licence comments starting /*! are kept unless you turn that option off.

How do I minify CSS?

Choose the CSS tab, paste a stylesheet or upload a .css file, and press Minify. Besides removing comments and whitespace, it drops the last semicolon in each rule, shortens six-digit hex colours whose pairs repeat (#ffffff to #fff), removes units from zero lengths (0px to 0) and leading zeros (0.5 to .5). Untick Shorten values to keep values exactly as written.

How do I minify HTML?

Choose the HTML tab, paste the markup or upload an .html file, and press Minify. Comments are removed, runs of whitespace collapse to one space, quotes are dropped from simple attribute values, default type attributes are deleted, and inline <script> and <style> blocks are minified as JavaScript and CSS. Each of those can be switched off under Options.

Does it detect the language automatically?

It suggests one. When you paste code that clearly looks like another language, such as CSS while the HTML tab is selected, the tool switches tabs for you and says so, with one tap to switch back. Code that could be either is left on the tab you chose.

Is the minified output safe to use in production?

It's built to be: the tool tokenizes your code, never edits the inside of strings, template literals or regular expressions, and keeps any whitespace whose removal could change the result, including the line breaks semicolon-free JavaScript depends on. Its JavaScript output was checked against hundreds of real library files by parsing before and after and comparing the syntax trees. Still test it where it will run, as with any build step.

How much space does minification save?

It depends on how much of the file is comments, indentation and line breaks. Heavily commented, deeply indented code often shrinks by a third or more, while code that's already compact barely changes. The tool shows the exact byte savings and, in browsers that support it, the gzip size before and after, which is closer to what actually travels over the network.

Should I minify if my server already uses gzip or Brotli?

Yes, the two work together. Compression shrinks repeated patterns like indentation very effectively, so the saving after compression is smaller than the raw percentage suggests, but a minified file still compresses to fewer bytes than the original, and removed comments never have to be sent at all. Compare the two gzip figures to see the real difference for your file.

Does it rename variables or obfuscate code?

No. This tool removes whitespace and comments and shortens a few CSS values; it does not rename variables, mangle function names or remove unused code. That keeps it safe for any code you paste, but a build-time minifier such as Terser or esbuild will make JavaScript smaller still.

Why does my minified JavaScript still have line breaks?

Because removing them would change what the code does. JavaScript inserts semicolons automatically at some line breaks, so code written without semicolons, a return followed by a value on the next line, or a ++ at the start of a line all depend on the break. The minifier keeps exactly those breaks and joins everything else. Ending statements with semicolons lets it put more of the code on one line.

Is my code uploaded to a server?

No. All minification happens in your browser, using a small tokenizer written in JavaScript; nothing leaves your device. Your settings are remembered on this device, and your current input is kept in this tab's session storage so it survives navigating away and back.

Is minified code harder to debug?

Yes. Code ends up on one or a few very long lines, so error messages point at column numbers instead of readable lines. Keep the original file for editing, and if you minify as part of a build, have the build tool write a source map so browser dev tools can show the original code. This tool doesn't generate source maps.

Can I minify JSON or un-minify code here?

JSON is valid JavaScript, so the JavaScript tab minifies it safely, but the JSON formatter is the better tool: it validates the JSON, minifies it and can pretty-print it again. This page doesn't beautify HTML, CSS or JavaScript; your editor's formatter (Prettier, for example) restores readable layout, though not the comments that minification removed.

Advertisement