# JavaScript Beautifier & Minifier - Format JS, TS & JSON

> Free online JavaScript formatter: beautify or minify JS, TypeScript, JSX and JSON with 2/4-space or tab indent and line width. Handles regex, templates, ASI.

- URL: https://qilingtools.com/en/js-format
- Category: Developer Tools (https://qilingtools.com/en/dev)
- Tags: [Compression](https://qilingtools.com/en/tags/compress), [Developer](https://qilingtools.com/en/tags/dev), [Code Formatting](https://qilingtools.com/en/tags/format), [Frontend](https://qilingtools.com/en/tags/frontend)
- Last updated: 2026-10-26
- Price: Free, no sign-up
- Privacy: Runs locally in the browser; files are never uploaded

A minified script squeezed onto one line, inherited code with messy indentation, or a TypeScript or JSON snippet you just want to read — paste it here and get neatly laid-out code. The formatter is hand-written: a complete tokenizer first recognises strings, template literals (including nested ${} expressions), regular expressions versus division, comments, numbers and JSX; then indentation is recomputed from bracket nesting, lines break after semicolons and blocks, spacing around operators, commas and keywords is normalised, objects and arrays that exceed the line width are expanded, and long arrays of numbers or strings are filled up to the width. Only whitespace changes: no semicolons are added or removed, quotes and names are untouched, the output has exactly the same token sequence as the input, blank lines are kept (at most one in a row), and formatting twice gives the same result. TypeScript generics, type annotations, optional parameters, non-null assertions, decorators, private fields and JSX are handled, and valid JSON is detected and fully expanded. Minify mode strips comments and extra whitespace (optionally keeping /*! license comments) but keeps a line break wherever automatic semicolon insertion (ASI) depends on it, so semicolon-free code keeps its meaning. Everything runs locally in your browser.

## How to use

1. Paste JavaScript, TypeScript, JSX or JSON into the input box
2. Choose Beautify or Minify and set the indent (2/4 spaces or tab) and line width
3. Review the result, then copy it or download a .js / .json file

## Features

- Hand-written tokenizer: regex, template literals and comments done right
- TypeScript generics, annotations, decorators and JSX
- 2 / 4 spaces or tab indent; 80 / 100 / 120 line width
- Whitespace-only changes, idempotent output
- Minifier keeps ASI-relevant line breaks
- JSON detected and fully expanded
- Before/after size comparison
- Runs locally, code never uploaded

## FAQ

### Can formatting change what my code does?

No. Only spaces, line breaks and indentation change — no semicolons are added or removed, quotes and names stay as they are, and the token sequence is identical to the input. New line breaks are only inserted after semicolons, brackets and commas, where automatic semicolon insertion cannot kick in. We tested it on a large set of real npm package sources: formatted and minified output passes node --check and keeps the same tokens.

### Does it support TypeScript, JSX and JSON?

Yes. TypeScript generics (such as Map<string, T[]> or <T,>() =>), type annotations, optional parameters x?, non-null assertions x!, interfaces, type aliases, enums and decorators are laid out correctly. JSX elements are kept exactly as written and re-indented as a whole, and valid JSON input is detected and expanded level by level.

### How is this minifier different from a bundler?

It is a light minifier: comments and redundant whitespace are removed, but variables are not renamed and dead code is not eliminated, so savings are moderate. In exchange it is safe, fairly readable and needs no build step. For the smallest possible bundles use esbuild or Terser in your project. Line breaks that matter for ASI are kept, so semicolon-free code still works.

### Is my code uploaded?

No. Tokenizing, formatting and minifying all run in your browser with no network requests, so it is fine to paste internal code or config files that contain secrets.

## Related tools

- [JSON Formatter](https://qilingtools.com/en/json): Free online JSON formatter: beautify or minify, validate with the exact line and column of any error, browse a collapsible tree, sort keys and escape strings.
- [Base64 Encode/Decode](https://qilingtools.com/en/base64): Free online Base64 encoder and decoder: UTF-8 safe, optional URL-safe variant, convert text to Base64 and back in real time. Processed locally, never uploaded.
- [URL Encode/Decode](https://qilingtools.com/en/url-encode): Free online URL encoder and decoder with encodeURIComponent and encodeURI modes. Escapes Chinese, spaces and special characters. Real-time and local, no upload.
- [JWT Decoder](https://qilingtools.com/en/jwt): Free online JWT decoder: decode the header and payload of a JSON Web Token, show expiry and issued-at times, all locally without uploading the token.
- [Timestamp Converter](https://qilingtools.com/en/timestamp): Free online Unix timestamp converter: convert timestamps and dates, auto-detect seconds or milliseconds, and show local, UTC, ISO 8601 and relative time.
- [Hash / Checksum](https://qilingtools.com/en/hash): Free online hash calculator: SHA-1, SHA-256, SHA-384 and SHA-512 of text or any file through the browser crypto API. Files never leave your device.
- [UUID Generator](https://qilingtools.com/en/uuid): Free online UUID generator: create RFC 4122 UUID v4 in bulk with a cryptographic RNG. Options for uppercase, no hyphens and braces, with one-click copy.
- [Base Converter](https://qilingtools.com/en/base-convert): Free online number base converter: convert between binary, octal, decimal, hexadecimal and any base 2–36. Uses BigInt for huge integers, computed locally.
