Zig Language Formatter
Format and beautify Zig source code — brace placement, operator/comma spacing (leaving strings, character literals, and comments untouched), block-depth indentation, and optional trailing commas on multi-line lists, matching zig fmt conventions. Includes basic bracket-balance validation. Runs entirely in your browser.
Input
Output
| Issue |
|---|
| No data yet |
Guides
Paste unformatted Zig source and get back code with consistent spacing, brace placement, and block-depth indentation — matching zig fmt conventions as closely as a browser-based, regex-driven formatter can. Strings, character literals, line comments, block comments, and multi-line (\\) strings are recognized and left byte-for-byte untouched; only the surrounding code gets reformatted. A quick validation pass flags unbalanced braces, parentheses, or brackets. Everything runs locally in your browser.
How to use it
- Paste your Zig source, or upload a
.zigfile. - Choose 4 spaces (the
zig fmtdefault), 2 spaces, or Tabs for indentation. - Turn on Add trailing commas to multi-line arg/field lists to append a trailing comma to the last item of a struct literal, array, or argument list that spans multiple lines — off leaves your original list endings untouched.
- Check the Validation panel for any bracket-balance issues, then copy or download the formatted result.
What it formats
- Brace placement: moves a bare
{on its own line up onto the previous line (fn foo()\n{→fn foo() {). - Spacing around binary operators (
+ - * / % == != <= >= && || << >> ++ **), compound assignment (+= -= *= /= …), commas, semicolons, and after:in type annotations — while leaving unary-/*/&untouched. if/while/for/switch/defer/catch/orelse/try/comptimeand similar keywords get a space before(or{;else/struct/enum/union/errorget consistent brace spacing too.- Re-indents every line by net brace/paren/bracket depth, and collapses runs of blank lines to one (removing a stray blank right after
{or right before a closing}/)/]).
Does it validate the code semantically?
No — this checks bracket balance only (unmatched or missing {}/()/[], an unterminated block comment), not whether the Zig actually compiles. For real validation, use zig build or zig ast-check.
Is my code uploaded anywhere?
No. Segmenting, spacing, and re-indenting all run locally in your browser; your Zig source is never sent to a server.
Need to format a different systems language?
Use the Lua Code Formatter or the Go Formatter for other hand-rolled, browser-side formatters, or the Elixir Code Formatter if your project mixes Zig with a BEAM-language backend.