Tabs and spaces

Tabs to spaces and back. A tab advances to the next stop rather than inserting a fixed number, which is why every other converter misaligns your columns. Nothing you type here leaves your browser. It is worked out on your own device, so there is nothing to send and nothing to log — which matters more for text than for most things, because people paste in work they are not supposed to paste anywhere.

A tab is a stop, not a number of spaces

Almost every tool converts a tab by replacing it with a fixed number of spaces. That is right only when the tab happens to sit at the very start of a line.

A tab advances to the next tab stop — the next multiple of the tab width. After four characters, with a width of eight, a tab inserts four spaces and not eight:

InputProper, to the stopReplacing with 8
name⇥valuename····valuename········value
a⇥b⇥ca·······b·······ca········b········c
⇥indented········indented········indented

Of seven realistic lines, five come out differently. The one that matches is the indented one — the case where the tab is at the start, which is the case the naive method was designed around.

Which is why columns fall apart

Tab-separated data is the thing people most often want to convert, and it is the thing the naive method breaks. Every row has fields of different lengths, so every row needs a different number of spaces to reach the same column. Replace each tab with a fixed count and the columns line up only where the fields happen to match.

This page does it properly and shows you the naive version beside it when the two differ, so you can see what you were about to get.

Width is a preference, not a fact

Four and eight are both common; two is common in some languages. The width is not stored in the file — a tab is one character and what it looks like depends entirely on what is displaying it.

That is the real argument for converting to spaces: spaces look the same everywhere. It is also the argument against, because the information about what was a tab is gone once you do.

Where to go next