Format C# code

Paste C# and copy the same program with clean indentation, one statement per line and the brace style you pick — string literals and #directives are kept as they were.

Runs locally in your browser
Copy

How to format C# code in the browser

Paste C# and the tool returns the same program with consistent indentation, one statement per line, a chosen brace style and optional line wrapping. Only whitespace is rewritten: string literals, verbatim and interpolated strings, comments and #directives come back exactly as written, so the output is the same C# program, just easier to read.

The formatter runs entirely in this browser tab and the code is never uploaded. It does not compile, validate or repair syntax: a broken file comes back broken, only laid out consistently.

  1. Paste the C# code into the box and press C# Code Formatting, or Ctrl/⌘+Enter. Every run replaces the previous output.
  2. Choose the indentation (tab or 2, 3, 4, 8 spaces), how many blank lines to keep, the brace style, and whether long lines should wrap at 80 or 120 characters.
  3. Press Copy to take the result, or Clear to empty both panes before the next snippet.
  4. Wrapping only breaks lines after commas, and the continuation is indented one level deeper; pick No wrapping if every statement should stay on one line regardless of length.

What the formatter changes — and what stays the same

What the formatter changes

Formatting is a whitespace rewrite. The sequence of tokens in the output is identical to the input: string literals, verbatim strings such as @"He said ""hi""", interpolated strings such as $"total {sum}", comments and the operators ?., ?? and ??= all survive untouched, and preprocessor lines such as #region, #if and #pragma stay at the start of their own line.

Braces follow the selected style: Allman puts every opening brace on its own line, K&R keeps it on the line of the statement, method or type, and the third style does the same while starting else, catch and finally on a new line.

Options in practice

Blank lines are truncated to the selected limit, from removing them entirely to keeping all of them — useful after pasting code that arrived with runs of empty lines. Short initializer groups stay compact: { 1, 2, 3 } and new { Name = "x" } are not exploded into several lines.

Line wrapping breaks only after commas. When a call or declaration exceeds the chosen width, the continuation is indented one level deeper; No wrapping keeps every statement on one line regardless of length.

What it does not do

It does not compile, validate or lint. Missing semicolons, unbalanced braces and unresolved types are carried over as they are, so the formatter cannot tell whether a file builds.

The code never leaves the browser tab: everything runs locally, so the tool also works with the network disconnected once the page has loaded. A 200 KB snippet is processed in a few tens of milliseconds, which is comfortable for files pasted from an editor.

Recent tools: