Skip to main content
Preparing workspace

Code Beautifier

Re-indent or compact JavaScript, JSON, CSS, HTML, XML and SQL up to 500,000 characters. Invalid JSON comes back with the exact line and column.

Still loading. If the tool doesn’t appear, reload this page.

About this tool

Code Beautifier

Instantly format, clean up and beautify messy JavaScript, JSON, CSS, HTML, XML and SQL — or compact it again.

Code Beautifier re-indents a messy snippet — JavaScript, JSON, CSS, HTML, XML or SQL — into readable, consistently nested code, and compacts it again on demand. Indentation for the JavaScript, CSS and HTML family is produced by js-beautify; JSON is parsed with the browser's own parser so a syntax error is reported with its exact line and column, and SQL is re-laid-out one clause per line with parenthesised sub-queries indented. It is for developers reading minified output, a log line or a snippet pasted out of a chat.

How to use Code Beautifier

  1. Paste a snippet into the Your code box — the limit is 500,000 characters — or press Detect language to have the tool guess what you pasted.

  2. Set Language to JavaScript / TypeScript, JSON, CSS / SCSS / LESS, HTML, XML / SVG or SQL, pick the Action (Beautify or Minify), choose an Indent width of 2, 4 or 8 spaces, and tick Uppercase SQL keywords when the language is SQL.

  3. The Formatted code box rewrites itself as you type, with Output lines, Input size, Output size and Size change beside it. Use Copy result, which flips to Copied!, Download to save the file shown under Download name such as formatted.js or formatted.json, or Reset to return to the example.

Why use Code Beautifier

  • Six languages, one box

    JavaScript, JSON, CSS, HTML, XML and SQL, with automatic language detection from the snippet's shape.

  • Errors located, not just reported

    Invalid JSON comes back with a line and column, so you go straight to the trailing comma.

  • Safe JavaScript compaction

    Comments and indentation are removed but line breaks are kept, so automatic semicolon insertion cannot change behaviour.

Common use cases

  • Make a one-line JSON API response readable, and find the exact character where an invalid payload breaks
  • Re-indent a SQL query copied out of an ORM log so the joins and WHERE conditions are visible
  • Expand a minified CSS or HTML fragment enough to see what a third-party widget is actually injecting

Frequently asked questions

Does beautifying code change what it does?

No. Beautifying only alters whitespace and line breaks, never tokens, so the program is identical. The one place whitespace matters in JavaScript is automatic semicolon insertion, which is why this tool's minify mode keeps every line break rather than collapsing the file onto one line.

Link to answer
How many spaces should I indent with?

Two is the most common default — it is what Prettier, the Google JavaScript style guide and the Node.js codebase use. Four suits Python-influenced teams and PHP's PSR-12. The width matters far less than being consistent across a repository, which is why most teams commit an .editorconfig or a Prettier config rather than arguing.

Link to answer
Why does my JSON fail to parse?

The three usual causes are a trailing comma after the last item, single quotes instead of double quotes, and unquoted property names — all legal in JavaScript object literals but forbidden by RFC 8259. This tool reports the line and column where the parser stopped, which is normally one character past the real mistake.

Link to answer
Is this a replacement for a real minifier?

No. Terser or esbuild rename variables, drop dead branches and rewrite expressions, typically cutting 40–60% off a bundle; this tool only removes comments and indentation, which is closer to 10–20% and completely reversible. Use it to read code, and use a build-step minifier to ship it.

Link to answer