Free Minify Online

Minify JavaScript with Terser, CSS with CSSO and HTML safely, or beautify minified code. Shows the bytes saved. Runs in your browser, nothing uploaded.

No login. Files processed for your request and discarded. Free to use. Files processed & discarded →

Compress PDF — it's free or choose from 130+ tools

130+ Free Tools
— Files Processed
— Happy Visitors
— Pages Explored
0 Files Stored

JavaScript, CSS and HTML Minifier

Part of Text tools: See all Text tools.

What is Minify?

This tool minifies or beautifies JavaScript, CSS and HTML. Minify makes code as small as possible for production: JavaScript goes through Terser, which parses the code, removes comments and whitespace, simplifies expressions and can shorten local variable names; CSS goes through CSSO, which removes comments and whitespace, shortens colors and values and merges rules where that is safe; HTML goes through html-minifier-terser, which removes comments, collapses runs of whitespace to one space and minifies inline style and script blocks. Beautify does the reverse and re-indents minified code with js-beautify so you can read it. The status line shows the size before and after, in bytes.

How to use Minify

  1. Choose the language: JavaScript, CSS or HTML.
  2. Paste your code into the Code box.
  3. Click Minify for the smallest output, or Beautify to re-indent minified code with 2 spaces, 4 spaces or a tab.
  4. Leave Keep license comments ticked if the code has a /*! ... */ copyright or license header. For JavaScript, untick Shorten local variable names if your code depends on function or variable names at run time.
  5. Read the status line for the size saved or for the line and column of a syntax error, then use Copy result or Download.

Why use this tool?

Comments, indentation and long local names help people read code but add bytes that every visitor downloads. Minifying a stylesheet or script before you upload it to a theme, CMS, landing page or email template reduces what the browser has to fetch and parse. Beautify is for the opposite job: reading a minified third-party script, a theme's compressed CSS or a one-line HTML export when you need to debug or review it.

Minify — In-Depth Guide

Minification removes everything a browser does not need: comments, indentation, line breaks and, for JavaScript, long local names. If your site is built with Vite, esbuild, webpack or a similar bundler, it almost certainly minifies already, and you should keep doing it there. A standalone minifier is useful for the cases a build step does not cover: a snippet pasted into a CMS or theme settings, a stylesheet for an email template, a small script on a static page, or checking what a minifier will do to a piece of code before you add it to a build.

Minification and server compression (gzip or Brotli) work together. Compression is very good at squeezing repeated text, so the saving you see in the status line here is larger than the saving over the network once the file is compressed. Minification still helps because it removes things compression cannot, such as comments and long variable names, and because the browser has less code to parse. To see the real effect, compare the transferred size of the file in your browser's developer tools before and after. This tool does not produce source maps, so keep the readable original in version control and minify a copy.

Minifiers that only use search and replace are risky. Deleting everything after // breaks any string that contains https://, and joining lines breaks JavaScript written without semicolons: let m = n followed by ++n on the next line means something different once the line break is gone. Template literals and regular expressions cause similar problems. Parser-based tools such as Terser and CSSO avoid this because they understand the language. The things that still need care are code that relies on names at run time, CSS that depends on the exact order of duplicated rules, and HTML layouts with inline-block elements, where whitespace between tags affects spacing.

Beautify is for reading code, not restoring it. It is the quickest way to make sense of a minified library when you are debugging an error, to review a theme's compressed CSS or to inspect a one-line HTML export. Names shortened by a minifier stay short. To compare two versions of a file, beautify both with the same indent and paste them into Text Diff. JSON, XML, SQL and YAML have their own formatters on this site, which also check the syntax.

Frequently asked questions

What does Minify change in JavaScript?
Terser reads the code as JavaScript, so it knows what is a string, a regular expression, a template literal or a comment. It removes comments and whitespace, rewrites expressions into shorter equivalents (for example x * 2 becomes 2*x and simple if/else blocks become ternaries) and, with Shorten local variable names ticked, renames variables and parameters inside functions to one or two letters. In a normal script, top-level names are kept so other scripts on the page can still call them. If the code uses import or export it is treated as an ES module, where top-level names can be shortened too because they are private to the module.
Can minifying break my code?
Because Terser parses the code, URLs such as https://example.com inside strings, // inside regular expressions and lines without semicolons are handled correctly. Code can still behave differently if it depends on names at run time: reading Function.prototype.name or a class name, or older dependency-injection code that reads parameter names. In that case untick Shorten local variable names. A syntax error stops the run and the status line shows the line and column. Always test the minified file before you deploy it.
What does Minify do to CSS?
CSSO removes comments and whitespace, shortens colors (#ff0000 becomes red), drops units on zero (0px becomes 0), collapses repeated shorthand values (padding: 10px 10px 10px 10px becomes padding:10px) and can merge or reorder rules when the result is the same. It is not a validator: a declaration the browser would ignore anyway, such as an empty value, may simply be dropped. SCSS and LESS are not supported, so compile them to CSS first.
What does Minify do to HTML?
It removes comments, except conditional comments and comments that start with <!--!, and collapses each run of spaces and line breaks to a single space. It never removes the space completely, so words and inline elements do not run together. Text inside pre and textarea is kept exactly, self-closing slashes such as <br/> are kept, and inline style and script blocks are minified as well. Templates with server code such as PHP or Jinja usually pass through unchanged, but check the result; minifying the rendered HTML is the safest option.
What does Beautify do?
It re-indents code with js-beautify, using 2 spaces, 4 spaces or a tab, and puts statements, rules and tags on their own lines. It cannot bring back comments or the original variable names that a minifier removed. For HTML, a line break added between two inline elements can occasionally show up as a small space on the page.
Are license comments kept?
Yes, when Keep license comments is ticked (the default). In JavaScript, comments that start with /*! or contain @license or @preserve are kept; in CSS, comments that start with /*! are kept. Untick it to remove every comment.
Is my code uploaded?
No. The four open-source libraries (Terser, CSSO, html-minifier-terser and js-beautify) are served from gotoolsonline.com and load in your browser the first time you click Minify or Beautify. Your code is processed on your device and is not sent to our server. Very large files, several megabytes, can take a few seconds.

Also try

Related tools that work well with this one: