FormatCodes
Home/Zig Tools/Zig Formatter

Zig Formatter

Format and validate Zig code online for free with the official zig fmt, right in your browser.

Local browser processing
No sign-up required
Powered by official zig fmt
Language
Zigmain.zig
zig fmt style is fixed: 4-space indent · no configurable optionsQuick format
InputEditable
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
OutputZig valid49 lines · 969 B
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const std = @import("std");
const Allocator = std.mem.Allocator;
const Node = struct {
value: i32,
next: ?*Node,
pub fn init(value: i32) Node {
return .{ .value = value, .next = null };
}
};
const LinkedList = struct {
head: ?*Node = null,
allocator: Allocator,
pub fn init(allocator: Allocator) LinkedList {
return .{ .allocator = allocator };
}
pub fn push(self: *LinkedList, value: i32) !void {
const node = try self.allocator.create(Node);
node.* = Node.init(value);
node.next = self.head;
self.head = node;
}
pub fn sum(self: *const LinkedList) i32 {
var total: i32 = 0;
var current = self.head;
while (current) |node| {
total += node.value;
current = node.next;
}
return total;
}
};
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
var list = LinkedList.init(allocator);
try list.push(1);
try list.push(2);
try list.push(3);
std.debug.print("Sum: {d}\n", .{list.sum()});
}
UTF-8 · 4-space indent · zig fmtLocal processing · Ready
How It WorksZig
Overview
This Zig formatter cleans up code with inconsistent indentation or mixed styles into a standard format, powered by a WebAssembly build of zig fmt — the output is identical to running the zig fmt command locally. Everything runs locally in your browser; your code never leaves your device.
Use Cases
Format Zig code pasted from docs or generated by AIClean up legacy code with inconsistent indentationCheck whether Zig syntax is correctUnify a team's Zig code style
Steps
123
Paste or uploadAuto-formattedGet the result

Related Tools

Related Guides

Frequently Asked Questions

Search Tools

Search 55+ formatting, conversion, minification, diffing, and generation tools