Skip to content
Latchkey

Prettier tabWidth and useTabs

tabWidth sets how many spaces a level of indentation uses; useTabs switches to hard tabs.

These two options decide indentation. tabWidth defaults to 2 and useTabs to false, which suits most JavaScript and TypeScript projects.

What it does

tabWidth is the number of spaces per indentation level, default 2. useTabs (default false) makes Prettier indent with tab characters instead of spaces; when useTabs is true, tabWidth determines how wide a tab is assumed to be for alignment. Both are plain config options.

Common usage

.prettierrc.json
// .prettierrc.json
{
  "tabWidth": 2,
  "useTabs": false
}

Options

OptionWhat it does
tabWidth (default 2)Spaces per indentation level
useTabs (default false)Indent with tabs instead of spaces
--tab-width <n>Set tabWidth on the CLI
--use-tabsEnable tabs on the CLI

In CI

Decide tabs vs spaces once and commit it, because mixing editor defaults with Prettier output is a classic source of CI drift. Use overrides if one folder (for example Go or Makefiles handled by a plugin) needs tabs while the rest uses spaces.

Common errors in CI

Files that pass locally but fail prettier --check in CI usually mean an editor reformatted with a different tabWidth than the committed config. The fix is to remove the editor-level setting and let .prettierrc be authoritative. Makefiles and other tab-sensitive files should be in .prettierignore unless a plugin handles them.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →