Code Formatters

Format source code consistently without installing anything. Most formatters here run Prettier, the widely used open-source code formatter, in your browser.

Popular Code Formatters

All Code Formatters (15)

About Code Formatters

Prettier parses your code into a syntax tree and prints it again with its own consistent style, so the output does not depend on how the input was laid out. These tools use Prettier 3 with its default options and two-space indentation. Because the code must parse first, a syntax error is reported with its line and column instead of being formatted.

The Java, C# and PHP formatters are simpler: they re-indent lines by bracket depth, reading each language's strings and comments so that braces inside them are ignored. They are useful for tidying pasted code whose indentation was lost, but they keep your line breaks and do not change spacing inside a line.

Which tool to use

Each Prettier-based formatter loads the parser for one language, so choose the page that matches your file: the TypeScript Formatter for type annotations, the Flow Formatter for Flow, the Vue and Angular formatters for component templates, and the LWC Formatter where attribute values in braces must stay unquoted. Plain JavaScript and JSX go to the JavaScript Beautifier. Pasting a file into the wrong formatter usually ends in a syntax error at the first construct the parser does not know.

Frequently asked questions

Which style do the Prettier-based formatters use?

Prettier 3 defaults with two-space indentation: double quotes, semicolons and an 80-character print width.

Why did formatting fail?

The code could not be parsed. The error shows the line and column; check for a missing bracket, a stray character or the wrong formatter for the language.

Do the formatters need an internet connection?

Once. Prettier is loaded from this site the first time you run a Prettier-based formatter. Your code is formatted in your browser and is not sent anywhere.

Common use cases

  • Tidying a snippet before pasting it into documentation
  • Reading minified or generated code
  • Checking whether code parses at all
  • Normalising formatting before comparing two versions

Example

function hi(n) {
  return n > 1 ? "many" : "one";
}

Prettier output for function hi(n){return n>1?"many":"one"}.