⌘

Code Minifier

Minify code content you provide.

0Words
0Characters
0Sentences
0mReading time
Choose a file or fill the fields, then click Run tool.

About Code Minifier

Sometimes you just need a snippet smaller and on one line, such as a CSS block for an email template, a bookmarklet draft, or a style rule for a CMS field that strips line breaks. This minifier does quick whitespace and comment removal for small pieces of code. It is not a build-tool replacement.

How it works

Three regular-expression steps run in order. First, every block comment from /* to */ is removed. Second, lines that begin with // are deleted. Third, all runs of whitespace, including line breaks, collapse into single spaces, and the result is trimmed. The tool does not parse the language, rename variables or remove spaces around braces. A // comment placed after code on the same line is not removed, and once lines are joined it can comment out everything after it. Whitespace inside strings is collapsed too.

How to use Code Minifier

  1. Type or paste the text you want to process in the text box above.
  2. Select “Run tool” and check the result before copying or downloading it.

Worked example

Input CSS over five lines: /* buttons */, .btn {, color: red;, padding: 4px 8px;, }. Output: .btn { color: red; padding: 4px 8px; } on a single line. The block comment is gone, and the line breaks and indentation became single spaces, but the spaces around the braces remain.

Tips for a better result

  • Move end-of-line // comments in JavaScript onto their own lines, or delete them, before minifying. Otherwise the joined line can silently disable code.
  • Check that strings and template literals do not rely on repeated spaces or line breaks, because those collapse into one space.
  • For production JavaScript or CSS bundles, use a real minifier such as Terser, esbuild or cssnano. This tool is meant for small snippets.

Frequently asked questions

Can I use it for HTML?

It will collapse whitespace in HTML, but HTML comments are not removed, and whitespace inside pre or textarea elements is collapsed too. That can change how the page looks. Review the output before using it.

Why did my JavaScript stop working after minifying?

The likely cause is a // comment at the end of a code line. After all lines are joined into one, everything following that comment is treated as part of it. Remove such comments, or use a parser-based minifier.

Is a URL like https://site.com treated as a comment?

Only lines whose first non-space characters are // are deleted, so a URL inside code or a string is kept. A block comment pattern inside a string, however, would be removed.

What to check

A formatted or parsed result is not proof that code is secure, correct or production-ready. Never paste production secrets.

Read the Privacy Policy for information about local processing, connected services and advertising.