Skip to main content

Code Formatter

Re-indent brace-based source code with a token-aware rewriter.

Written by Golam Rabbani, Founder & Lead Engineer

Brace-based formatter — re-indents and re-wraps lines around { } ; , based on token structure.

How to use this code formatter

  1. Paste a snippet from any brace-based language: JavaScript, TypeScript, Java, C#, Go, Rust, PHP, or similar.
  2. Pick the indent size — 2 spaces, 4 spaces, or tab.
  3. Press Format to rewrite the snippet with consistent indentation around { } ; , and ( ).
  4. Copy the formatted code or hit Reset to clear and try a new snippet.

About this code formatter

The code formatter works on the structural symbols that brace-based languages share: { } indicate a block, ; ends a statement, and , separates items in a list. It tokenises your source, preserves string literals, template strings, and comments verbatim, then re-emits the snippet with one statement per line and consistent indentation after every opening brace. Closing braces dedent and sit on their own line, unless they are followed by else, catch, finally, or while, in which case they stay attached to the next keyword.

It is not a language-specific parser, so it does not understand things like Python's indent-based blocks or YAML — use the dedicated SQL, HTML, XML, JSON, and YAML tools for those. For everyday house-keeping on JS/TS/Java/C#/Go/Rust/PHP snippets pasted from logs, code-review screenshots, or single-line minified bundles, it produces a clean, readable layout in one click.

For example, the input "function add(a,b){return a+b;}" becomes: function add(a, b) { return a + b; }

Strings, regex literals, and inline comments inside the snippet keep their exact original text — only the surrounding whitespace and indentation are rewritten.

FAQ

Which languages does it support?
Anything with C-style braces and semicolons: JavaScript, TypeScript, Java, C, C++, C#, Go, Rust, PHP, Kotlin, Swift, Dart, and similar. Indent-based languages like Python or YAML are out of scope.
Will it rewrite my strings?
No. Single-quoted, double-quoted, and backtick template strings are detected and passed through unchanged. Only whitespace and indentation outside of literals are reformatted.
How is it different from Prettier or Black?
Those are full-blown language-aware formatters that ship as a CLI. This tool is a small in-browser helper for paste-and-go cleanup; it does not understand language grammar, so it will not, for example, rewrap long argument lists.
Are comments preserved?
Yes. Both // and /* */ comments are detected and re-emitted in place. # is recognised for Bash/Python-style line comments so it also survives the round trip.
Is my source code uploaded?
No. The formatter runs in your browser. Nothing is sent to a server.
Why is my Python or YAML coming back broken?
Python and YAML use indentation rather than braces to indicate blocks. Use the dedicated YAML validator or paste Python into a Python-aware tool instead — this formatter is only safe for brace-based languages.