How to use Spaces to Tab
- Paste your code or text into Your text. The sample is a function indented with 4 spaces per level.
- Set Spaces per tab to the indent size your text uses, from 1 to 16. The default is 4.
- Keep Only convert indentation at the start of lines ticked to change indentation only, or untick it to convert spaces anywhere.
- Copy the result, shown in a monospaced font.
What it does and when to use it
Spaces and tabs both indent text, but projects usually pick one. This tool converts in the tabs direction. It is useful when:
- a project, linter or formatter expects tab indentation;
- you are writing a Makefile, where recipe lines must start with a tab;
- you copied code from a web page or chat that turned its tabs into spaces;
- you want smaller files or prefer to let each reader choose the tab width in their editor.
The default “start of lines only” setting is the safe one. It changes only the indentation, which is where tabs belong, and leaves alignment inside lines alone.
Unticking it is mainly useful for plain-text tables where columns were separated by a fixed number of spaces and you want tab-separated values to paste into a spreadsheet. Check the result, because runs shorter than the size stay as spaces.
To go the other way, use Tab to Spaces. To remove indentation completely, use Trim Lines with Start only. To tidy uneven spacing inside lines first, run Remove Extra Spaces.
How it works
With the default setting, the tool looks at the run of spaces at the start of each line. It divides its length by the size: the whole part becomes that many tabs, and the remainder stays as spaces after them. Tabs already in the text are left alone.
With the option unticked, every group of exactly size spaces anywhere in a line is replaced by one tab, working from left to right. A run of 5 spaces with size 4 becomes a tab plus 1 space. The conversion happens in your browser.
Worked examples
Four-space Python. A function whose lines are indented 0, 4 and 8 spaces, plus a stray line indented 6, at size 4. The result has 0, 1 and 2 tabs, and the stray line becomes one tab plus 2 spaces before “odd”. The leftover spaces flag the uneven indent.
Two-space code. The same structure indented 2 and 4 spaces, at size 2, gives one and two tabs per line.
Spaces inside a line. “Name Age City” (4 spaces, then 5) with the option unticked and size 4 becomes Name, tab, Age, tab, space, City: two tabs, plus the 1 space left over from the run of 5.
Limits and tips
- Spaces that follow a tab at the start of a line are not converted, because only spaces that begin the line are checked.
- The result looks the same as before only in an editor whose tab width equals the size you chose.
Frequently asked questions
How many spaces per tab should I choose?
What happens to leftover spaces?
Why are the spaces inside my lines not converted?
Which languages or tools need tabs?
How do we know nothing is uploaded? Test it yourself on the privacy proof page.