About Spaces to Tabs
Spaces to Tabs converts runs of spaces into tab characters, the standard way to normalise indentation when a file has drifted to using spaces and the rest of the project uses tabs. You choose how many spaces make one tab, and every run of exactly that many spaces is replaced by a single tab.
The replacement is exact rather than greedy. With the default width of four, four leading spaces become one tab, eight spaces become two tabs, and a run of three spaces is left untouched because it does not fill a whole tab. The spaces count is raised to a minimum of one, so a value of zero cannot produce an empty pattern.
One detail may surprise you: the replacement runs across the whole text, not only at the start of lines, even though the tool is described for leading spaces. Interior runs of spaces inside a line are converted just the same. There is no reverse direction here - converting tabs back to spaces is left to the matching tool.
How to use Spaces to Tabs
- 1 Paste the text whose spaces you want to convert.
- 2 Set the Spaces per tab field to your indentation width.
- 3 Run the tool to read runs of exactly that many spaces as tabs.
Frequently asked questions
How many spaces become one tab?
Exactly as many as the Spaces per tab field says, by default four. A run of eight spaces becomes two tabs, and a run of three spaces is left alone because it does not fill a whole tab.
Does it only convert indentation at the start of lines?
No. The replacement applies everywhere in the text, so interior runs of spaces inside a line are converted too, even though the description mentions leading spaces.
Can I convert tabs back to spaces here?
No. This tool only goes from spaces to tabs. For the reverse direction you need the separate tabs-to-spaces tool.
What does an empty input return?
An empty result. With no text there are no spaces to convert, so the output is empty.
Free, online, and private
Free to use
Spaces to Tabs is completely free. There is no account to create, no login, and no hidden charge or usage limit.
Runs online in your browser
It is a free online tool that runs entirely in your browser. Nothing to download or install — open the page and start using it right away.
Your data stays private
All processing happens locally on your device. Your input is never uploaded, stored, or tracked, so it never leaves your browser.
How Spaces to Tabs behaves in detail
These are the specifics of this implementation — the exact ranges, defaults and fixed settings you are working with.
| Parameter | Value |
|---|---|
| Input | a Text textarea starting with four spaces then the word indented, and a Spaces per tab number field starting at four |
| Output | every run of exactly that many consecutive spaces is replaced by a single tab character |
| Clamp | the spaces count is raised to a minimum of one before the replacement is built |
| Default | four leading spaces become a single tab |
| Exactness | a run of eight spaces with a width of four becomes two tabs, and a run of three spaces is left untouched |
| Missing text | an empty text returns an empty result |
Compiled from the implementation of this tool and checked against it by itoolnet.
What Spaces to Tabs does not do
Knowing the edges of a tool saves more time than another list of its features. These are the cases where it will not do what you might expect.
- Only runs of exactly N spaces are converted. A run of three spaces under a width of four is left alone, and a run of six becomes one tab plus two leftover spaces - the tool does not treat a partial run as a whole tab.
- The replacement happens everywhere in the text, not only at the start of lines, despite the description mentioning leading spaces. Interior runs of spaces inside a line are converted just the same.
- The spaces count has a minimum of one but no effective upper clamp in the run, so a large value simply stops matching ordinary indentation, and there is no reverse tabs-to-spaces direction in the same tool.
Tested and documented by itoolnet, the team that builds and maintains this site.