Skip to content

Code Formatter

More options

The preset that sets braces, spacing and the 80- or 100-column limit.

Indent width
Formatted code
—
Lines out
—
Lines rewritten
—

Pick the language, paste the code and the formatted version appears below. Go goes through gofmt, C++ and Java through clang-format with a style such as LLVM or Google, Dart through dart_style and Lua through StyLua. For example, int add(int a,int b){return a+b;} becomes int add(int a, int b) { return a + b; } in LLVM style.

About this tool

Code reviews go faster when layout arguments are settled by a formatter, not by people. This page runs the same formatters the language communities use: gofmt for Go, LLVM clang-format for C++ and Java, dart_style for Dart and StyLua for Lua, each compiled to WebAssembly and loaded only when you pick its language. Paste a snippet or open a source file and you get the reformatted text plus counts of lines in, lines out and lines rewritten. For C++ and Java you choose one of the seven built-in clang-format presets and an indent width; Lua offers tabs or spaces. The code never leaves the page. One limit: the formatters only reflow valid code, so a missing brace or a stray parenthesis returns the parser's error with its line and column instead of a partial result.

How to use it

  1. Choose the language

    C++, Java, Go, Dart or Lua. Only that formatter's WebAssembly file is downloaded, the first time you use it.

  2. Set the style

    For C++ and Java pick a clang-format preset (LLVM, Google, Chromium, Mozilla, WebKit, Microsoft, GNU) and an indent width; for Lua pick tabs, 2 or 4 spaces. Go and Dart have one official layout and no options.

  3. Paste or open the code

    Type into the box or open a .cpp, .java, .go, .dart or .lua file from your disk; the file is read locally.

  4. Copy the result

    The formatted code updates as you edit. If the parser finds a syntax error, the message names where it stopped.

Examples

Go hello world through gofmt

Language
Go
Source code
package main import "fmt" func main(){ fmt.Println("hi") }
clang-format style
LLVM
Indent width
Style default
Lua indentation
Tabs

Result Formatted code: package main

import "fmt"

func main() {
fmt.Println("hi")
}

Lines out: 7
Lines rewritten: 2

  1. gofmt: tabs for indentation, spaces for alignment, imports and declarations in canonical layout
  2. Read 5 lines of Go; parsed into a syntax tree
  3. Printed 7 lines; 2 differ from the input

The body gains a tab indent, the brace moves onto the func line and blank lines separate package, import and func, exactly as go fmt writes it.

C++ in LLVM style

Language
C++
Source code
#include <iostream> int add(int a,int b){return a+b;} int main(){std::cout<<add(2,3)<<std::endl;return 0;}
clang-format style
LLVM
Indent width
Style default
Lua indentation
Tabs

Result Formatted code: #include <iostream>
int add(int a, int b) { return a + b; }
int main() {
std::cout << add(2, 3) << std::endl;
return 0;
}

Lines out: 6
Lines rewritten: 5

  1. clang-format with BasedOnStyle: LLVM (the style's own indent width)
  2. Read 3 lines of C++; parsed into a syntax tree
  3. Printed 6 lines; 5 differ from the input

The one-statement add() stays on one line because LLVM style allows short functions there; main() is split and indented by two spaces.

A Java loop in Google style

Language
Java
Source code
public class Hello{public static void main(String[] args){for(int i=0;i<3;i++){System.out.println(i);}}}
clang-format style
Google
Indent width
Style default
Lua indentation
Tabs

Result Formatted code: public class Hello {
public static void main(String[] args) {
for (int i = 0; i < 3; i++) {
System.out.println(i);
}
}
}

Lines out: 7
Lines rewritten: 7

  1. clang-format with BasedOnStyle: Google (the style's own indent width)
  2. Read 1 line of Java; parsed into a syntax tree
  3. Printed 7 lines; 7 differ from the input

Every nested block steps in by two spaces, the indent the Google Java guide asks for, and the operators gain spaces.

How it is calculated

formatted text = printer(parse(source), style options), where printer is gofmt, clang-format, dart_style or StyLua

Each formatter parses the source into a syntax tree and prints it again from scratch, so the output depends on the code's structure, not on its old whitespace. gofmt has no settings: tabs indent, spaces align, and imports sit in their own block. clang-format reads a style made of BasedOnStyle plus overrides; this page sends the chosen preset and, if you set one, IndentWidth. dart_style uses a two-space indent and an 80-column page. StyLua defaults to tabs and a 120-column line, and the page can switch it to 2 or 4 spaces. Lines rewritten counts output lines that do not appear in the input.

Sources

When not to use it

  • Do not use it to check that code compiles; formatters parse syntax but never type-check.
  • Skip it when your repository has a .clang-format or stylua.toml file, because those custom settings are not read here.
  • It does not format Python, Kotlin, Rust, Swift or Ruby.

Common mistakes

  • Pasting a fragment without its enclosing function or class, which makes the Go and Dart parsers stop.
  • Picking Java but leaving the LLVM preset, which keeps short methods on one line instead of Google's block layout.
  • Expecting gofmt to accept a spaces setting; Go's canonical layout always indents with tabs.
  • Mixing two languages in one paste, such as C++ with an embedded Lua chunk.

Frequently asked questions

Which Go formatter should I use?

gofmt, which ships with the Go toolchain and is what go fmt runs. Its output is the canonical layout the Go project expects, so there is nothing to configure: tabs for indentation, spaces for alignment, and a fixed placement for braces and imports. This page runs gofmt compiled to WebAssembly, so a pasted file comes out the same as on your machine.

How do I format Java code in Google style?

Choose Java, then the Google preset. clang-format then indents each block by two spaces, puts opening braces on the same line and limits lines to 100 columns, which follows the Google Java Style Guide's main layout rules. It does not reorder imports into Google's groups or rewrite Javadoc, so a dedicated google-java-format run can still differ on those details.

What does the C++ formatter change in LLVM style?

LLVM style indents by two spaces, keeps lines within 80 columns, adds spaces around binary operators and after commas, and keeps a one-statement function on a single line. In the example above, int add(int a,int b){return a+b;} becomes int add(int a, int b) { return a + b; }, while main() is split over four lines.

How does the Dart formatter lay out code?

It runs dart_style, the library behind the dart format command. It indents blocks by two spaces and fits code into an 80-column page, splitting long argument lists across lines when they do not fit. There are no style choices: the Dart team keeps one layout so every project reads the same.

Is there a Lua formatter that uses spaces instead of tabs?

StyLua indents with tabs by default, and this page lets you switch it to 2 or 4 spaces with the Lua indentation control. It also adds spaces inside table braces, so local t={1,2,3} becomes local t = { 1, 2, 3 }, and puts the body of a for loop on its own indented line.

What is the difference between a code beautifier and a formatter?

In practice the names mean the same thing: a program that rewrites the whitespace and line breaks of source code without changing what it does. The formatters here parse the code first, so they refuse invalid syntax rather than guess, and running one twice gives the same text both times.

Cite this tool

Using this tool in an assignment, article or report? Copy a citation, or a link for your website.

APA

Tools Directory Editorial Team. (2026, December 2). Code Formatter. Tools Directory. Retrieved December 4, 2026, from https://directory.milunir.com/developer-tools/code-formatters/code-formatter/

MLA

Tools Directory Editorial Team. “Code Formatter.” Tools Directory, 2 Dec. 2026, https://directory.milunir.com/developer-tools/code-formatters/code-formatter/. Accessed 4 Dec. 2026.

Chicago

Tools Directory Editorial Team. “Code Formatter.” Tools Directory. Last modified December 2, 2026. Accessed December 4, 2026. https://directory.milunir.com/developer-tools/code-formatters/code-formatter/.

Link<a href="https://directory.milunir.com/developer-tools/code-formatters/code-formatter/">Code Formatter – Tools Directory</a>