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.
- Replaces every tab wherever it sits, so alignment tabs inside a line are handled as well as leading indentation.
- Converts a whole file in one pass, keeping the indentation consistent throughout rather than being applied line by line.
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.
- Expands each tab to a fixed count rather than to the next tab stop, so tabs used for mid-line alignment shift out of position.
Examples
Best Practices & Notes
Best Practices
- Confirm your project's actual tab width before assuming 4 spaces preserves visual alignment exactly.
- Match the width to whatever your editor was displaying, so the file looks the same after conversion as it did before.
- Convert the entire file at once, since a partially converted file mixes both styles and reads worse than either alone.
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.
- Converting a file that uses tabs for column alignment rather than indentation, where fixed-width expansion pulls the columns apart.
Tips
- Use Convert Spaces to Tabs to reverse this operation.
- Spaces render identically everywhere, which is why most style guides prefer them; a tab's width only ever existed in the editor's display settings.