Overview
Introduction
Switching a codebase or config file's indentation style from spaces to tabs means precisely converting every indentation level.
This tool converts every 4-space run to a tab.
What Is Spaces to Tabs?
A converter that replaces every run of exactly 4 consecutive space characters with one tab character.
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 Spaces to Tabs Works
A regex matching 4 consecutive spaces is replaced globally with a tab character.
The transformation happens synchronously in JavaScript the moment you type, with no network round trip involved.
When To Use Spaces to Tabs
Use it when converting space-indented source code or config files to tab 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 Tabs to Spaces and Whitespace Remover.
Features
Advantages
- Simple, predictable conversion for standard 4-space indentation.
Limitations
- Only matches exact 4-space runs; 2-space or inconsistent indentation won't convert as expected.
- Doesn't distinguish leading indentation from spaces elsewhere in a line.
Examples
Best Practices & Notes
Best Practices
- Verify your source actually uses consistent 4-space indentation before converting, or the result may be uneven.
Developer Notes
The replacement regex is built dynamically as `{width} spaces`, defaulting to 4, so it matches runs of exactly that many consecutive spaces rather than any arbitrary run length.
Spaces to Tabs Use Cases
- Converting a space-indented file to tab indentation
- Normalizing indentation style across a codebase
- Preparing code for a style guide that requires tabs
Common Mistakes
- Running this on 2-space-indented code, which won't match the 4-space pattern.
Tips
- Use Convert Tabs to Spaces to reverse this operation.