Minifiers

Code Minifiers to Shrink CSS, JavaScript, HTML, JSON and More

Minifying removes the characters a browser or parser does not need, such as comments, indentation and line breaks, so files download faster. These minifiers cover web assets, data formats and source code. Paste your code, compare the before and after size, then copy or download the result. Nothing is uploaded.

Minifiers guides

Short explainers that show how the maths or the file format works, and which tool to reach for next.

All articles

All 13 minifiers, by type

Each group explains what its tools are for, so you can find the right one without scrolling a long list.

Web assets (4)

The files every page load downloads: stylesheets, scripts, HTML and SVG graphics. Minifying these is the most common way to cut page weight, and it is best done on a copy while you keep the readable source.

Data and configuration formats (4)

Compact JSON, XML, YAML and GraphQL for APIs, feeds and config files. JSON is parsed first, XML keeps text and CDATA intact, and YAML keeps indentation because its structure depends on it.

Source code (3)

Strip comments and formatting whitespace from Java and C# while leaving strings intact, or use the general Code Minifier to trim whitespace from PHP, Ruby or SQL, which does not parse those languages.

Formatters for the return trip (2)

The opposite direction: add indentation and line breaks back so dense code or messy text is easy to read and edit. Covers GraphQL queries and schemas and Markdown documents.

Why use FreeToolsVerse minifiers

Copy or download in one click

Most minifiers let you copy the result to the clipboard or download it with the right extension, such as minified.js or minified.svg, ready to drop into a project.

Strings and comments handled safely

The Java, C# and GraphQL minifiers leave string literals untouched, C# keeps preprocessor directives on their own lines, and XML keeps CDATA, so code does not change meaning.

Keep the license line

The JavaScript Minifier can preserve /*! license */ comments and choose whether to shorten variable names, so legal notices survive minification.

Errors instead of broken output

Invalid JSON, unterminated strings and unclosed XML tags raise a clear message rather than quietly returning damaged code you might deploy.

A formatter for the reverse

Keep readable source as the original and use the GraphQL and Markdown formatters, or the formatters in Developer Tools, when you need to read minified text again.

How these tools are built and checked

Minifiers that change structure are the risky ones, so they are tested. Automated checks confirm that minified JSON and YAML load to the same data, that strings, CDATA sections, text inside SVG labels and C# preprocessor lines survive, and that invalid input raises an error. JavaScript is handled by Terser. The CSS, HTML and PHP, Ruby or SQL tools are simpler text-based minifiers, and the Code Minifier page says plainly that it does not parse syntax. Minified output should always be treated as a build artifact: keep the formatted source, and test the minified file where it will run.

Read our editorial standards

Minifiers: frequently asked questions

How much smaller will my file get after minifying?

It depends on how much of the file is comments and indentation. Heavily commented, well-indented code shrinks a lot and compact code only a little. Servers usually also compress text with gzip or Brotli, so the saving over the wire is smaller than the before and after figure shown.

Does minifying change what my code does?

It should not. Terser keeps JavaScript behavior the same, JSON is parsed and rewritten with identical values, and XML text is preserved. The CSS, HTML and PHP, Ruby or SQL options work on text rather than a parsed syntax tree, so review their output and test before you deploy.

Why can't YAML be minified to a single line?

In YAML, indentation defines structure, so collapsing lines would change or break the data. The YAML Minifier removes comments, blank lines and trailing spaces but keeps indentation, block scalars and quoted strings. Automated tests check that the result loads to the same data as the original.

Does the JavaScript Minifier replace my build tool?

It is useful for a one-off script or a quick check, using the same Terser engine that many build tools use. A bundler also combines files, removes unused exports and can write source maps. This tool minifies the code you paste and does not create a source map.

Is it safe to minify PHP, Ruby or SQL with the Code Minifier?

Only with care. It trims each line and joins them without parsing the language, so a line comment (// in PHP, # in Ruby, -- in SQL) can swallow the code after it. Remove comments first and run the result before using it. Python is excluded because indentation carries meaning.

Can I turn minified code back into readable code?

You can restore indentation and line breaks with a formatter, but comments and original variable names are gone for good. Keep your readable source as the master copy and deploy the minified copy. The GraphQL Formatter here, and the CSS, HTML, JavaScript, JSON, SQL, XML and YAML formatters in Developer Tools, can make minified text readable again.

Will the minifier delete my copyright or license comment?

It depends on the tool. The JavaScript Minifier keeps /*! */, @license and @preserve comments by default, and the XML and SVG minifiers have a remove comments option. The CSS Minifier keeps /*! */ comments by default and removes the rest, and the HTML Minifier keeps conditional comments, so check the output if your license requires a notice.