Format Code Now
/

C Formatter and Beautifier

FV-32

Paste C code to format it with clang-format. Choose the indent, a base style such as LLVM or Google, and a line width. The formatter runs in your browser.

Runs in your browser. Nothing is uploaded.

C code

Formatted C

How to use it

  1. Paste your C code into the input box, or open a .c or .h file.
  2. Pick the indent: 2, 3, 4 or 8 spaces, or a tab.
  3. Choose a base style and a line width. LLVM with 80 columns is the default.
  4. Copy the formatted code or download it as a .c file.

What runs in your browser

The formatter is clang-format, the tool from the LLVM project, compiled to WebAssembly. It reads your code as text and rewrites the layout: indentation, brace placement, spacing around operators and pointer stars, and line breaks in long statements. Your code is never compiled or run. The first format downloads the formatter, about 2.5 MB, and the page keeps it for the rest of the visit.

Base style, indent and width

The base style sets the overall look: LLVM, Google, Chromium, Mozilla, WebKit, GNU or Microsoft. GNU puts braces on their own indented lines, while LLVM and Google keep them on the line. The indent and line width you pick override the style. Choosing Tab uses a tab with a tab width of 4. Setting the width to No limit stops clang-format from wrapping long lines at all.

It formats, it does not check

clang-format does not compile, so it does not report most syntax errors. Broken code comes back laid out as well as the formatter can guess, which can look odd around the mistake. If the output looks strange, look for a missing brace or semicolon near it. Includes, macros and comments are kept, but long lines may be broken at a different place when you change the width.

Questions people ask

How do I format C code online?

Paste the code and the result appears as you type, using clang-format with your chosen indent, style and width. Copy it or download it as a .c file. The formatter runs in your browser, and the first run downloads it, so allow a moment.

Which style should I choose?

Pick the one your project already uses. LLVM is the default and keeps braces on the same line. Google and Chromium are similar. GNU puts braces on separate lines. The indent and width you choose here override the style, so you can start from any base.

Can it format C++ or header files too?

It treats the text as C. Plain C headers work the same way. C++ code often formats acceptably because clang-format handles both, but C++ specific layout such as templates and access specifiers is only reliable when the code is read as C++, so use a C++ formatter for that.

Does it fix errors in my code?

No. It does not compile or check syntax, and it never changes what the code does. Missing semicolons and braces are not reported. Broken code is still laid out as far as the formatter can read it, so odd output near a line is a hint to look there for a mistake.

How do I use tabs instead of spaces?

Choose Tab in the Indent list. The formatter then indents with tabs and treats a tab as 4 columns when it decides where to wrap. Choosing any number of spaces turns tabs off, and existing tab indentation in your code is replaced.

Why did my long lines change?

clang-format wraps statements that are longer than the line width. Raise the width to 100 or 120, or choose No limit, to keep them on one line. Short statements are not joined back together unless the style allows it, such as a short if on one line.

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; the indent and line-width choices override it. The code is treated as C. It formats the text you give it and does not compile it, so it does not report most syntax errors: broken code comes back formatted as well as clang-format can guess. Macros, includes and comments are kept, and line breaks inside long statements may move to fit the 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.