Automatically Convert Tabs to Spaces in IntelliJ IDEA

Learn how to configure IntelliJ IDEA to use spaces instead of tabs automatically, verify existing files, and fix mixed indentation.

Before you start

IntelliJ IDEA applies automatic tab-to-space conversion locally through the editor settings. No online service, plugin, or project upload is required. The change can be made globally for new files or scoped to the current project. A code style scheme controls the indentation rules, so the first step is to identify the active scheme and the file types you want covered.

Make sure the editor is open but no unsaved file changes are at risk. Indentation settings do not immediately rewrite every open file. Existing tab characters remain until you reformat the code or use a conversion action.

Step-by-step instructions

The exact settings window differs slightly between IntelliJ IDEA versions and between project-level and IDE-level settings, but the core controls remain the same.

To set automatic spaces for new and future code, start with the Settings or Preferences dialog. On Windows or Linux, open File then Settings. On macOS, open IntelliJ IDEA then Settings or Preferences depending on your version. Navigate to Editor, then Code Style.

Select the language you are working with, such as Java, JavaScript, TypeScript, HTML, JSON, or YAML. On the Tabs and Indents tab, find the Use tab character option and make sure it is cleared. Set Tab size and Indent to the same number of spaces if you want a consistent layout.

For frontend or document-like files, check the relevant nested section. HTML, JSON, YAML, and similar formats may have their own code style entries under the same Code Style group. Changing the general editor setting alone does not override a language-specific scheme.

Apply the chosen scheme at the intended scope. IDE-level settings affect all projects on that installation, while project-level settings travel with the project. If the workspace uses a shared team code style, edit that stored scheme instead of creating a conflicting personal override.

Existing files do not change automatically when you clear Use tab character. Reformat a file or selected scope to apply the rule, or run a conversion that replaces tab characters with spaces without changing the logical structure.

A more direct conversion is available from the main menu through Edit, then Convert Indents, then To Spaces. This applies to the current selection or the whole file when nothing is selected. For project-wide changes, reformat the relevant files after the code style is configured, or use an inspection and bulk fix if the project already has indentation rules enabled.

Check the output

Show whitespace in the editor to verify the result. Tab characters appear with a different whitespace marker from spaces, so you can distinguish them quickly. Search for a tab character in an affected file to confirm whether any remain.

Reopen the code style dialog and confirm that Use tab character is still cleared for the language you edited. Indentation conversion does not preserve tab stops as layout spacing; a tab that was used for visual alignment is replaced by spaces according to the configured tab size. This can change alignment inside comments or multiline text, so review cosmetic alignment rather than assuming it is untouched.

Common problems and next steps

If new lines still use tabs, the active file is probably governed by a different language code style or a project scheme. Open the file, check which scheme applies, and update that scheme rather than only the general IDE setting.

If a project-wide conversion seems to do nothing, IntelliJ IDEA may be excluding generated or third-party folders from formatting. Review the project structure and scope settings before expecting vendor or output files to change.

If spaces appear instead of tabs in some files and not others, mixed schemes are the likely cause. Standardize the code style across languages, then convert existing files once. Keep a project formatter configuration under version control when team consistency matters.

If keyboard indentation still inserts a tab, check whether the editor is temporarily using a different action or whether an enabled plugin overrides indentation behavior. The most reliable test is to type a new indented line in the target file after saving the code style change.