Tabs to Spaces

Replaces every tab character with 4 spaces, useful for converting tab-indented code or config files to space indentation. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-22

Overview

Introduction

Switching a codebase's indentation style from tabs to spaces means replacing every tab with a consistent number of spaces.

This tool does that in one step.

What Is Tabs to Spaces?

A converter that replaces every tab character with 4 spaces.

It runs entirely client-side as part of this site's String Tools collection, so nothing you paste is ever uploaded to a server.

How Tabs to Spaces Works

Every tab character is replaced globally with a fixed run of 4 space characters.

The transformation happens synchronously in JavaScript the moment you type, with no network round trip involved.

When To Use Tabs to Spaces

Use it when converting tab-indented source code or config files to space indentation.

It's a fast way to get the answer without opening a code editor, a REPL, or writing a one-off script just to check.

Often used alongside Spaces to Tabs and Whitespace Remover.

Features

Advantages

  • Simple, predictable conversion at a standard 4-space width.

Limitations

  • Uses a fixed 4-space width regardless of your editor's configured tab width, which can shift alignment if your project uses a different width.

Examples

Converting indented code

Input

	indented
	code

Output

    indented
    code

Each tab becomes 4 spaces.

Best Practices & Notes

Best Practices

  • Confirm your project's actual tab width before assuming 4 spaces preserves visual alignment exactly.

Developer Notes

The replacement is a straightforward `input.replace(/\t/g, " ".repeat(width))` with a default width of 4.

Tabs to Spaces Use Cases

  • Converting a tab-indented file to space indentation
  • Normalizing indentation style across a codebase
  • Preparing code for a style guide that requires spaces

Common Mistakes

  • Assuming 4 spaces always matches your editor's visual tab width.

Tips

  • Use Convert Spaces to Tabs to reverse this operation.

References

Frequently Asked Questions