Skip to content

Formatter

Biome is an opinionated formatter that has the goal to stop all ongoing debates over styles. It follows a similar philosophy to Prettier, only supporting a few options to avoid debates over styles, turning into debates over Biome options. It deliberately resists the urge to add new options to prevent bike-shed discussions in teams so they can focus on what really matters instead.

The language agnostic options supported by Biome are:

  • indent style (default: tab): Use spaces or tabs for indention
  • tab width (default: 2): The number of spaces per indention level
  • line width (default: 80): The column width at which Biome wraps code

Other formatting options are available for specific languages as well. See the configuration options for details.

Use the formatter with the CLI

Section titled Use the formatter with the CLI

By default, the formatter checks the code and emit diagnostics if there are changes in formatting:

  • npm
  • yarn
  • pnpm
  • Bun Logo bun
  • deno
	
Terminal window
npx @biomejs/biome format ./src
	
Terminal window
yarn dlx @biomejs/biome format ./src
	
Terminal window
pnpm dlx @biomejs/biome format ./src
	
Terminal window
bunx @biomejs/biome format ./src
	
Terminal window
deno run -A npm:@biomejs/biome format ./src

If you want to apply the new formatting, pass the --write option:

  • npm
  • yarn
  • pnpm
  • Bun Logo bun
  • deno
	
Terminal window
npx @biomejs/biome format --write ./src
	
Terminal window
yarn dlx @biomejs/biome format --write ./src
	
Terminal window
pnpm dlx @biomejs/biome format --write ./src
	
Terminal window
bunx @biomejs/biome format --write ./src
	
Terminal window
deno run -A npm:@biomejs/biome format --write ./src

Use the --help flag to know what are the available options:

  • npm
  • yarn
  • pnpm
  • Bun Logo bun
  • deno
	
Terminal window
npx @biomejs/biome format --help
	
Terminal window
yarn dlx @biomejs/biome format --help
	
Terminal window
pnpm dlx @biomejs/biome format --help
	
Terminal window
bunx @biomejs/biome format --help
	
Terminal window
deno run -A npm:@biomejs/biome format --help

Or check the CLI reference section.

You may want to configure Biome using biome.json. The following defaults are applied:

biome.json
{
"formatter": {
"enabled": true,
"formatWithErrors": false,
"indentStyle": "tab",
"indentWidth": 2,
"lineWidth": 80,
"lineEnding": "lf",
"ignore": []
}
}

There are times when the formatted code isn’t ideal.

For these cases, you can use a format suppression comment:

example.js
// biome-ignore format: <explanation>

Example:

example.js
const expr =
// biome-ignore format: the array should not be formatted
[
(2 * n) / (r - l),
0,
(r + l) / (r - l),
0,
0,
(2 * n) / (t - b),
(t + b) / (t - b),
0,
0,
0,
-(f + n) / (f - n),
-(2 * f * n) / (f - n),
0,
0,
-1,
0,
];

Differently from other tools, Biome places options belong to a language in a different place of its configuration.

Following, the default applied to JavaScript files:

biome.json
{
"javascript": {
"formatter": {
"arrowParentheses":"always",
"jsxQuoteStyle": "double",
"semicolons": "always",
"trailingComma": "all",
"quoteProperties": "asNeeded",
"bracketSpacing": true,
"bracketSameLine": false
}
}
}