Code Formatter

Format JavaScript, TypeScript, HTML, CSS, Markdown, Python, Java, Go and C code with Prettier, Ruff, gofmt and clang-format, in your browser.

Runs in your browser. Nothing is uploaded.

How to use the Code Formatter

  1. Choose a language in Language - JavaScript, TypeScript, HTML, CSS (or SCSS and LESS), Markdown, Python, Java, Go or C and C++.
  2. Paste code into the left box, open a file, or press Load example. The formatted code appears on the right as you type.
  3. Adjust the options next to Language. Each language shows only the settings its formatter supports.
  4. If the code has a syntax error, the message gives the line and column and the spot is marked.
  5. Copy or download the result, with the right file extension for the language.

One formatter page for your whole stack

Consistent formatting makes code easier to read, review and diff. Most projects let a formatter decide indentation, line breaks and spacing, so nobody argues about style. But sometimes you need it outside your editor: code pasted from a chat, a snippet from documentation, a minified file you need to read, or a machine without your tools installed. Choose the language, paste the code and get the same output the standard formatter for that language would produce.

Languages and their formatters

  • JavaScript and TypeScript with Prettier, including JSX, TSX and modern syntax. Choose indent, line width, quotes, trailing commas and semicolons.
  • HTML with Prettier, including inline <script> and <style> blocks. The whitespace setting controls how strictly spaces around inline elements are kept.
  • CSS, SCSS and LESS with Prettier. Pick the dialect so nesting, mixins and variables are parsed correctly.
  • Markdown with Prettier, which tidies lists, headings, tables and code blocks and can rewrap paragraphs to a width.
  • Python with the Ruff formatter, a fast Black-compatible formatter. Line width starts at Black’s 88, with PEP 8’s 79 available.
  • Java, C and C++ with clang-format, using a style preset such as Google, LLVM, Chromium, Mozilla or WebKit, optionally with your own indent and column limit.
  • Go with gofmt, the one official style.

Options that match your project

Each language shows only the options its formatter has. The values are remembered in this browser, so the next time you open the page your settings are still there. If your project has a config file (.prettierrc, pyproject.toml, .clang-format), set the same values here and the output will match what your editor produces.

Errors with a location

Formatters need code that parses. When it doesn’t, the message names the problem with its line and column, and the position is marked in the input, so you can fix a missing bracket or quote and see the formatted result straight away.

Everything runs locally in a background worker, so the page stays responsive even with large files. To shrink code instead, use the Code Minifier.

Frequently asked questions

Which formatters does it use?

The ones projects actually use: Prettier for JavaScript, TypeScript, HTML, CSS, SCSS, LESS and Markdown; the Ruff formatter (compatible with Black) for Python; gofmt for Go; and clang-format for Java, C and C++. They run in your browser as JavaScript or WebAssembly, so the output matches what your editor or CI would produce with the same settings.

Why does the first format take a moment?

Each formatter is downloaded the first time you use its language, from a few dozen kilobytes for CSS up to about 1 MB for clang-format. A progress bar shows the size. After that it is cached and formatting is instant, even offline.

Can it make minified code readable again?

It restores line breaks and indentation, so the structure is clear again. It can't bring back original variable names or comments, because minifiers throw those away.

Why does Go have no options?

gofmt has one official style for all Go code: tabs for indentation and fixed spacing. That is the point of it, so the formatter offers no settings.

Is my code uploaded?

No. Formatting happens in a background worker in your browser, so private and proprietary code never leaves your device.

Tutorials

Tutorial · 4 min · beginner

How to format a React TSX component

Reformat a cramped React component written in TypeScript so its props, hooks and JSX are laid out cleanly and consistently.