Go Formatter (gofmt)

Paste your Go and get it back in the one standard Go style. The formatter is gofmt, the same tool that ships with Go, running in your browser, so your code stays on your device.

gofmt formats with tabs and needs no settings.

Format uses gofmt, the official Go formatter (tabs, no options).

Result

What gofmt does

Go has one official style, and gofmt is the tool that applies it. It fixes indentation, aligns struct fields and comments, and tidies spacing so every Go file looks the same. Because the style is fixed, there is nothing to configure. This tool runs gofmt in your browser and changes only the layout, never what the program does.

Why use our Go formatter

  • ·Free. No signup, no paywall, no limits.
  • ·Runs in your browser. gofmt runs locally as WebAssembly, so your code is never uploaded.
  • ·The real gofmt. Output matches what go fmt produces on your own machine.
  • ·No setup. No install and no Go toolchain needed to format a quick snippet.
  • ·Syntax highlighting. The editor colours keywords and types, and lets you collapse and expand blocks.

How gofmt formats Go

Format

Rewrites your Go with gofmt, the official Go formatter. It fixes indentation, alignment, and spacing to match the one standard Go style.

Beforefunc main(){fmt.Println(1)}Afterfunc main() { fmt.Println(1) }

One standard style

gofmt has no options on purpose. Every Go project uses the same layout, so there is nothing to configure. It always uses tabs for indentation.

BeforeMany personal stylesAfterOne shared Go style

Tabs for indentation

gofmt indents with tabs, which is the Go standard. Your editor can then show tabs at whatever width you prefer without changing the file.

BeforeMixed spaces and tabsAfterTabs, the Go way

When to format Go

gofmt helps whenever you have Go code that is not yet in the standard style. These are the cases that come up most:

  • ·Quick formatting without a toolchain. Format a snippet when Go is not installed on the machine you are on.
  • ·Cleaning up pasted code. Clean up Go copied from a forum, a blog post, or a chat.
  • ·Checking a snippet. See how gofmt would lay out a piece of code before you paste it in.
  • ·Learning Go. See the standard style while you are still learning the language.

Learn more about Go

Once your Go is formatted, these official references explain the language and the formatter behind this tool:

If you work across languages, these formatters run the same way, right in your browser:

Frequently asked questions

What is a Go formatter?
A Go formatter takes Go source code and rewrites it in the one standard Go style, with correct indentation, alignment, and spacing. This tool uses gofmt, the official formatter that ships with Go, so the result matches what go fmt would produce on your machine.
How do I format Go code?
Paste your Go into the input box and click Format. The clean version appears below. Click the copy button to copy it, or download it as a .go file.
Why are there no style options?
gofmt is opinionated on purpose. Go has one official style, so every project looks the same and there is nothing to configure. That is why this tool has a single Format button and no settings.
Does gofmt use tabs or spaces?
gofmt indents with tabs. That is the Go standard. Your editor can display tabs at any width you like, so the file stays standard while still looking the way you prefer.
Does formatting change how my Go program works?
No. gofmt only changes whitespace and alignment. Your packages, functions, and logic stay the same, so the program builds and runs exactly as before.
Is my Go code kept private?
Yes. The formatter is gofmt compiled to WebAssembly and runs entirely in your browser. Your code is never uploaded to a server or saved anywhere, so you can safely paste in code from a private project. Once the page has loaded you can even use it offline.