Skip to main content
L
Loopaloo
Buy Us a Coffee
All ToolsImage ProcessingAudio ProcessingVideo ProcessingDocument & TextPDF ToolsCSV & Data AnalysisConverters & EncodersWeb ToolsMath & ScienceGames
Guides & BlogAboutContact
Buy Us a Coffee
L
Loopaloo

Free online tools for developers, designers, and content creators. Your files are processed in your browser and are never uploaded - no accounts required. A few network utilities (like What's My IP and Currency Converter) call public APIs to do their job and say so on their pages.

support@loopaloo.com

Tool Categories

  • Image Tools
  • Audio Tools
  • Video Tools
  • Document & Text
  • PDF Tools
  • CSV & Data
  • Converters
  • Web Tools
  • Math & Science
  • Games

Company

  • About Us
  • Contact
  • Blog
  • FAQ

Legal

  • Privacy Policy
  • Terms of Service
  • Disclaimer

Support

Buy Us a Coffee

© 2026 Loopaloo. All rights reserved. Built with privacy in mind.

Privacy|Terms|Disclaimer
  1. Home
  2. Document & Text
  3. Code Minifier & Beautifier
Add to favorites

Code Minifier & Beautifier

Minify or beautify JavaScript, TypeScript, CSS, HTML, JSON, XML and SQL as you type, without touching strings or licences, and see the bytes saved.

Text processed locallyMore document & textJump to full guide
Related readingCode Minification: Reducing File Sizes for Faster Web Performance10 min

Initializing in your browser…

You might also like

JSON Formatter & Validator

Format, validate and minify JSON, JSONC or JSON5 as you paste, with exact numbers, precise error locations, a tree view, JSONPath queries and schema checks.

XML Formatter & Tools

Format, minify or convert XML to JSON as you type, with line-and-column error checks, a tree view and XPath queries that handle namespaces.

YAML Formatter & Converter

Format and validate YAML or convert between YAML and JSON as you type, keeping comments, anchors and exact numbers, with YAML 1.1 and 1.2 support.

Code Minifier & Beautifier: a worked example

You need to paste a small analytics snippet into a site's header field and want it as short as possible without breaking it.

JavaScript, 212 bytes

/*! analytics v2 | MIT */
// Track a page view
function track(page) {
  const url = "https://example.com/collect?p=" + page; // not a comment
  console.log("tracking", page)
  return fetch(url)
}
let retries = 3
What Code Minifier & Beautifier produces

Minified, Aggressive level, 127 bytes (40.1% smaller)

/*! analytics v2 | MIT */
function track(page){const url="https://example.com/collect?p="+page;return fetch(url)}
let retries=3

Both ordinary comments are gone, but the /*! licence comment stays. The // inside the URL string is part of the string, so it survives. The console.log call is a whole statement, so the Aggressive level removes it. Two line breaks remain. JavaScript can treat a line break as the end of a statement, so where a statement ends without a semicolon the break is kept rather than risk changing the program, and a note under the result says how many were kept.

About the Code Minifier & Beautifier

Paste JavaScript, TypeScript, CSS, HTML, JSON, XML or SQL to minify it for production or beautify it for reading. The result updates as you type and shows exactly how many bytes you saved, ready to copy or download.

How it works

Minifying removes everything a computer does not need, such as comments, indentation and line breaks, so files download faster. Beautifying does the opposite and lays compressed code out so a person can read it. This tool does both for seven languages, in your browser, and it is careful about the cases that trip up simple find-and-replace minifiers.

It reads the code before changing it. Each language is split into proper tokens first, so the tool knows the difference between a comment and two slashes inside a string, a URL in a CSS url() or a regular expression in JavaScript. Text inside strings, template literals, regular expressions and HTML <pre> blocks is never touched. In JavaScript, a line break is kept where removing it would change the meaning of the program, which happens when a statement ends without a semicolon; the tool tells you how many it kept and why. Licence comments that start with /*! or contain @license are kept, as most licences require.

Three levels. Safe removes comments and collapses whitespace, which is right for almost every file. Aggressive also removes console calls that stand as whole statements (a console call inside an expression is kept, since removing it would break the expression) and drops redundant semicolons before closing braces. Maximum also removes HTML conditional comments such as <!--[if IE]>. Each switch can be changed individually under More options. Variables are not renamed, because doing that safely requires analysing scopes across the whole program; use a build tool such as Terser or esbuild if you need that last step.

Beautify with your style. Beautify mode indents with 2 spaces, 4 spaces or tabs, puts one statement or declaration per line, and works for minified JSON, XML and SQL as well as code. For SQL, choose the dialect so quoted identifiers and backslash escapes are read correctly; MySQL treats a backslash inside a string as an escape and the others do not.

Honest numbers. Sizes are measured in bytes of UTF-8, the same as a file on disk, so the percentage saved matches the file you download. Minified output is often 20 to 60 percent smaller before compression; gzip or Brotli on your server then shrinks it further. Nothing is uploaded, so you can safely minify private source code.

How to use

  1. 1Choose Minify or Beautify, then pick the language. Open file detects the language from the file extension.
  2. 2Paste your code, open a file, or press Try an example to load a sample for the selected language.
  3. 3In Minify mode choose Safe, Aggressive or Maximum, or fine-tune the switches under More options.
  4. 4In Beautify mode choose 2 spaces, 4 spaces or tabs.
  5. 5Read the size saving above the result, then press Copy or download the file with the right extension.

Key features

  • Minify and beautify JavaScript, TypeScript, CSS, HTML, JSON, XML and SQL
  • Live results as you type, with no process button
  • Token-based processing that never alters strings, regular expressions or <pre> blocks
  • Line breaks that JavaScript needs are kept and reported
  • Licence comments preserved
  • Safe, Aggressive and Maximum levels, plus individual switches
  • Beautify with 2 or 4 spaces or tabs
  • SQL dialect awareness for identifier quotes and escapes
  • Byte-accurate size comparison and percentage saved
  • Copy, download, or feed the result back in as input

When to reach for this

  • Shipping a small script without a build step

    Minify a snippet, widget or bookmarklet before pasting it into a CMS, tag manager or HTML page.

  • Reading minified code

    Beautify a compressed stylesheet, script or JSON response to debug it or understand what a third-party file does.

  • Inlining critical CSS

    Minify the CSS you inline in a page head so it adds as few bytes as possible to every request.

  • Tidying SQL and XML

    Lay out a one-line SQL query or XML payload from a log so you can read and edit it, then minify it again if needed.

Tips & best practices

  • Keep the original, readable file in version control and treat minified output as a build artefact.
  • Serve minified files with gzip or Brotli compression; the two savings add up.
  • Use the swap button to beautify a file, edit it, and minify the edited version without copying back and forth.
  • If the size saving is small, the file probably has few comments and little indentation already; compression on the server will matter more.

Examples

  • A tracking snippet

    A 212-byte JavaScript function with a /*! MIT */ licence comment, two ordinary comments and a console.log minifies at the Aggressive level to 127 bytes. The licence stays, the URL containing // stays intact, and two line breaks are kept because the statements had no semicolons.

  • A CSS rule

    A 69-byte rule with a comment and a url("a//b.png") value becomes .btn{color:#fff;background:url("a//b.png")} at 43 bytes. The double slash inside the URL is not mistaken for a comment.

  • Beautifying JSON

    {"a":1,"b":[1,2]} in Beautify mode with 2 spaces becomes a seven-line document with each array item on its own line.

Frequently asked questions

Is minified code safe to use in production?

Yes, that is what it is for. The tool only removes comments and whitespace that do not affect behaviour, keeps line breaks that JavaScript relies on, and never changes strings or regular expressions. As with any build step, run your tests on the minified file before deploying.

Why is my minified JavaScript still on several lines?

JavaScript inserts semicolons automatically at some line breaks. If a statement ends without a semicolon, joining it to the next line can change what the code does, so the tool keeps that line break and reports it. Add semicolons to your source if you want a single line.

Does it shorten variable names?

No. Renaming variables safely requires understanding every scope in the program, which this tool does not attempt. For maximum compression of a large application, use a bundler with Terser or esbuild; for snippets and stylesheets, comment and whitespace removal gives most of the saving.

What do the Safe, Aggressive and Maximum levels change?

Safe removes comments and extra whitespace. Aggressive also removes console calls that are complete statements and the last semicolon before a closing brace. Maximum also removes HTML conditional comments. You can adjust each option separately under More options.

Why does the SQL dialect matter?

Databases quote names and escape strings differently. MySQL uses backticks and treats a backslash in a string as an escape; PostgreSQL and SQL Server do not. Choosing the right dialect makes sure strings and identifiers are recognised correctly, so nothing inside them is altered.

Is my code uploaded?

No. All processing happens in your browser, so private or proprietary code never leaves your computer.

Related tools and how they differ

  • JSON Formatter & Validator: Formats and validates JSON with exact numbers, error locations and a tree view.
  • SQL Formatter: Lays out SQL queries with keyword case and indentation options for reading and review.
  • XML Formatter & Tools: Formats and validates XML while preserving CDATA, comments and significant whitespace.

Further reading

  • Code Minification: Reducing File Sizes for Faster Web Performance10 min read

Private by design

Your text is processed locally in the browser. Nothing you paste or open is transmitted or logged.