clang-format Style Guide Matrix and Summaries
Have you ever tried to make sense of clang-format’s dozens of style options? Or tried to remember which one actually controls that one spacing quirk? Most guides out there just show examples without summarizing why one choice differs from another.
We created a table that lines up the formatting rules across the major style presets—LLVM, Google, Chromium, Mozilla, WebKit, Microsoft, and GNU, and summarizes what each option means with examples.
It’s meant to save time when you’re deciding which preset fits your code habits or when you’re tuning your own .clang-format.
clang-format Style Guide Matrix
| Feature / Style | LLVM | Chromium | Mozilla | WebKit | Microsoft | GNU | Obj-C (same as WebKit) | |
|---|---|---|---|---|---|---|---|---|
| Indent Width | 2 | 2 | 2 | 2 | 4 | 4 | 2 | 4 |
| Continuation Indent | 4 | 4 | 4 | 2 | 4 | 8 | 2 | 4 |
| Tab Width | 8 | 8 | 8 | 8 | 8 | 4 | 8 | 8 |
| Use Tabs | Never | Never | Never | Never | Never | Never | Never | Never |
| Brace Style | K&R | K&R | K&R | K&R | K&R | K&R | Allman | K&R |
| Namespace Indentation | No | No | No | No | No | Yes | Yes | No |
| Access Specifier Indent | 2 | 1 | 1 | 1 | 1 | 1 | 2 | 1 |
| Pointer Alignment | Right (int* p) |
Left (int *p) |
Right | Right | Right | Right | Left | Right |
| Reference Alignment | Same as Pointer | Same as Pointer | Same | Same | Same | Same | Same | Same |
| Column Limit | 80 | 80 | 80 | 99 | 80 | 120 | 79 | 80 |
| Space Before Control (if/for/while) | Yes | Yes | Yes | Yes | No | Yes | Yes | No |
| Space After C-style Cast | No | No | No | No | No | No | Yes | No |
Allow Short if on One Line |
False | True | False | True | False | True | False | False |
| Allow Short Functions on One Line | InlineOnly | InlineOnly | InlineOnly | InlineOnly | All | All | None | All |
| Break Before Braces (global) | Attach (K&R) | Attach | Attach | Attach | Attach | Attach | Allman | Attach |
| Indent Case Labels | True | True | True | True | False | True | True | False |
| Break Constructor Initializers | AfterColon | AfterColon | AfterColon | AfterColon | BeforeComma | BeforeComma | BeforeComma | BeforeComma |
| Allow All Arguments On Next Line | False | True | True | True | True | True | True | True |
| Indent Preprocessor Directives | None | None | None | None | AfterHash | None | None | AfterHash |
| Align After Open Bracket | Align | Align | Align | Align | DontAlign | Align | DontAlign | DontAlign |
| Align Consecutive Assignments | False | False | False | False | False | False | True | False |
| Align Consecutive Declarations | False | False | False | False | False | False | True | False |
| BinPack Arguments / Parameters | True | True | False | True | True | True | False | True |
| Keep Empty Lines at Start of Block | True | True | True | True | True | True | True | True |
| Allow Short Loops on One Line | False | True | False | True | False | True | False | False |
| Sort Includes | True | True | True | True | True | True | False | True |
| Max Empty Lines to Keep | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| Space Before Paren (Functions) | Never | ControlStatements | ControlStatements | ControlStatements | Never | ControlStatements | Always | Never |
| Space Before Paren (Control) | Always | Always | Always | Always | Never | Always | Always | Never |
| Use Tab for Alignment | Never | Never | Never | Never | Never | Never | Never | Never |
| Default Language Context | C++ | C++ | C++ | C++ | C++ / ObjC | C++ | C | ObjC |
Parameter-by-Parameter Explanations, Examples, and Variant Usage
Indent Width
Defines how many spaces a single indentation level uses.
Examples
// 2-space indent
if (x) {
foo();
}
// 4-space indent
if (x) {
foo();
}
Variants and which styles use them
- 2-space: LLVM, Google, Chromium, Mozilla, GNU
- 4-space: WebKit, Microsoft, Obj-C(WebKit)
Continuation Indent
How far continuation lines (e.g., wrapped function calls) are indented relative to the first line.
Variants and which styles use them
- 2: Mozilla, GNU
- 4: LLVM, Google, Chromium, WebKit, Obj-C(WebKit)
- 8: Microsoft
myFunction(longArgument1,
longArgument2); // example with continuation indent
Tab Width
How many spaces a tab represents. Usually irrelevant if tabs aren’t used.
- 8: LLVM, Google, Chromium, Mozilla, WebKit, GNU, Obj-C(WebKit)
- 4: Microsoft
Use Tabs
Controls whether indentation uses tab characters or spaces.
- Never: LLVM, Google, Chromium, Mozilla, WebKit, Microsoft, GNU, Obj-C(WebKit)
Brace Style
Determines placement of opening braces.
Variants and which styles use them
- K&R / Attach (brace on same line): LLVM, Google, Chromium, Mozilla, WebKit, Microsoft, Obj-C(WebKit)
- Allman (brace on next line): GNU
Examples
// K&R
if (x) {
foo();
}
// Allman
if (x)
{
foo();
}
Namespace Indentation
Specifies whether code inside a namespace is indented.
- No: LLVM, Google, Chromium, Mozilla, WebKit, Obj-C(WebKit)
- Yes: Microsoft, GNU
// Indented inside namespace (Yes)
namespace N {
void f();
}
// Not indented (No)
namespace N {
void f();
}
Access Specifier Indent
Indentation applied to public:, private:, etc.
- 1: Google, Chromium, Mozilla, WebKit, Microsoft, Obj-C(WebKit)
- 2: LLVM, GNU
class X {
public:
void f();
};
Pointer Alignment
Controls spacing relative to * or &.
- Left (
int *p): Google, GNU - Right (
int* p): LLVM, Chromium, Mozilla, WebKit, Microsoft, Obj-C(WebKit)
int *p; // Left
int* p; // Right
Reference Alignment
Same options and usage as pointer alignment in these presets.
Column Limit
Maximum line width before wrapping.
- 79: GNU
- 80: LLVM, Google, Chromium, WebKit, Obj-C(WebKit)
- 99: Mozilla
- 120: Microsoft
Space Before Control Parentheses
Whether to insert a space before parentheses in if, for, while.
- Yes: LLVM, Google, Chromium, Mozilla, Microsoft, GNU
- No: WebKit, Obj-C(WebKit)
// Yes
if (x) { ... }
// No
if(x) { ... }
Space After C-style Cast
Determines if a space follows (Type) casts.
- No: LLVM, Google, Chromium, Mozilla, WebKit, Microsoft, Obj-C(WebKit)
- Yes: GNU
(int)foo; // No
(int) foo; // Yes
Allow Short if on One Line
Controls collapsing if statements without braces onto one line.
- True: Google, Mozilla, Microsoft
- False: LLVM, Chromium, WebKit, GNU, Obj-C(WebKit)
if (x) foo(); // allowed when True
Allow Short Functions on One Line
Whether functions short enough to fit within column limits may stay on one line.
- InlineOnly: LLVM, Google, Chromium, Mozilla
- All: WebKit, Microsoft, Obj-C(WebKit)
- None: GNU
Break Before Braces
Defines global rule for brace placement.
- Attach (K&R): LLVM, Google, Chromium, Mozilla, WebKit, Microsoft, Obj-C(WebKit)
- Allman: GNU
Indent Case Labels
Whether case and default labels in a switch are indented.
- True: LLVM, Google, Chromium, Mozilla, Microsoft
- False: WebKit, Obj-C(WebKit)
- True (GNU): GNU
Break Constructor Initializers
Whether : in initializer lists breaks after or before.
- AfterColon: LLVM, Google, Chromium, Mozilla
- BeforeComma: WebKit, Microsoft, GNU, Obj-C(WebKit)
// AfterColon
Foo::Foo()
: x(1), y(2) {}
// BeforeComma
Foo::Foo()
: x(1)
, y(2) {}
Allow All Arguments On Next Line
Whether it’s permitted to move all arguments to the next line as a group.
- False: LLVM
- True: Google, Chromium, Mozilla, WebKit, Microsoft, GNU, Obj-C(WebKit)
Indent Preprocessor Directives
Determines if #define, #if etc. are indented.
- None: LLVM, Google, Chromium, Mozilla, Microsoft, GNU
- AfterHash: WebKit, Obj-C(WebKit)
#define FOO(x) // WebKit AfterHash:
(x + 1)
Align After Open Bracket
Determines if parameters or arguments align under the first after a line break.
- Align: LLVM, Google, Chromium, Mozilla, Microsoft
- DontAlign: WebKit, GNU, Obj-C(WebKit)
// Align
foo(arg1,
arg2);
// DontAlign
foo(
arg1,
arg2);
Align Consecutive Assignments / Declarations
Controls whether multiple statements align around = or types.
- True: GNU
- False: LLVM, Google, Chromium, Mozilla, WebKit, Microsoft, Obj-C(WebKit)
BinPack Arguments / Parameters
Whether to pack function arguments tightly on lines until column limit.
- True: LLVM, Google, Mozilla, WebKit, Microsoft, Obj-C(WebKit)
- False: Chromium, GNU
Keep Empty Lines at Start of Block
Whether to retain blank lines immediately after {.
- True: LLVM, Google, Chromium, Mozilla, WebKit, Microsoft, GNU, Obj-C(WebKit)
Allow Short Loops on One Line
Same as short if, but for loops.
- True: Google, Microsoft
- False: LLVM, Chromium, Mozilla, WebKit, GNU, Obj-C(WebKit)
for (int i = 0; i < n; ++i) foo(i); // allowed when True
Sort Includes
Automatically alphabetizes include directives.
- True: LLVM, Google, Chromium, Mozilla, WebKit, Microsoft, Obj-C(WebKit)
- False: GNU
Max Empty Lines to Keep
Collapses multiple consecutive blank lines to this number (usually 1) for compactness.
- 1: LLVM, Google, Chromium, Mozilla, WebKit, Microsoft, GNU, Obj-C(WebKit)
Space Before Parentheses (Functions)
Whether to put space before a function call’s (.
- Never: LLVM, WebKit, Obj-C(WebKit)
- ControlStatements: Google, Chromium, Mozilla, Microsoft
- Always: GNU
foo(x); // Never
if (x) { } // ControlStatements
foo (x); // Always
Space Before Parentheses (Control Statements)
Specifically controls if, for, while.
- Always: LLVM, Google, Chromium, Mozilla, Microsoft, GNU
- Never: WebKit, Obj-C(WebKit)
Use Tab for Alignment
Whether tabs can be used for aligning tokens (distinct from indentation).
- Never: LLVM, Google, Chromium, Mozilla, WebKit, Microsoft, GNU, Obj-C(WebKit)
Default Language Context
Sets baseline rules depending on expected language.
- C++: LLVM, Google, Chromium, Mozilla, Microsoft
- C++ / ObjC: WebKit
- C: GNU
- ObjC: Obj-C(WebKit)