Format Code Now
/

C++ Formatter and Beautifier

FV-42

Paste C++ and get it formatted by clang-format, compiled to WebAssembly and running in your browser. Choose a base style, the indent and the line width.

Runs in your browser. Nothing is uploaded.

C++ code

Formatted C++

How to use it

  1. Paste your C++, or open a .cpp or .h file or drop it on the input box.
  2. Pick a base style, an indent of 2, 4, 8 or a tab, and a column limit.
  3. Press Format.
  4. Copy the result or download it as a .cpp file.

Which styles are available

The base style sets brace placement, spacing and how access specifiers are indented. LLVM, Google, Mozilla, WebKit, Chromium, Microsoft and GNU are clang-format's built-in presets. Your indent and column limit then override the preset. If your project has a .clang-format file, copy the same base style and numbers here to get close output, since that file is not read.

Formatting is not compiling

clang-format lays out text. It does not parse C++ the way a compiler does, so missing semicolons, undeclared names and type errors pass without a message. Garbage in gives garbage out: broken code comes back formatted as well as the tool can guess. Includes, macros and comments are kept, and long statements wrap at the column limit.

Loading the formatter

The first run downloads the WebAssembly formatter, which is a few megabytes, and the page then keeps it for later runs. After that, formatting happens locally and does not need the network. The input is treated as C++ whatever you paste, so C code that is also valid C++ works too.

Questions people ask

How do I format C++ code online?

Paste the code, choose a style, and press Format. The output follows clang-format's rules for that style with your indent and column limit applied. The output follows clang-format rules for that style with your indent and column limit applied. Copy it or download it as a .cpp file.

Which clang-format version is this?

It is the clang-format build bundled in the page through a WebAssembly package. Its output can differ slightly from the version installed on your machine, especially for newer language features.

Does it report syntax errors?

No. It formats text and does not compile it. Use your compiler for errors. Badly broken code may be laid out oddly. It formats text and does not compile it, so use your compiler for errors. Badly broken code may be laid out oddly, because clang-format guesses.

Can I use my own .clang-format file?

Not directly. This page reads only the choices on screen. Pick the same base style, indent and column limit that your file uses to get a close match.

Why did my includes stay in the same order?

clang-format can sort includes, but this page leaves the order as you wrote it. Sorting changes meaning in some projects, so no reordering is done.

About this tool

Runs clang-format, the formatter from the LLVM project, compiled to WebAssembly in your browser. The base style sets brace placement and spacing, and your indent and line-width choices override it. It formats text and does not compile it, so it does not report syntax errors: broken code comes back laid out as well as clang-format can guess. Includes, macros and comments are kept, and long statements may be wrapped at the chosen width. The first run downloads the formatter, which is a few megabytes, and the page then keeps it for later runs.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.