Convert Tabs to Spaces

Switch indentation between tabs and spaces with a tab width you choose. Tab stops are calculated properly, so aligned columns stay aligned.

Tab stops, not blind replacement

Almost every online converter replaces each tab character with a fixed number of spaces. That is correct only when the tab is the first thing on the line. A tab in the middle of a line does not mean "insert four spaces" — it means "advance to the next tab stop", which is a different number of spaces depending on where you already are.

The practical consequence shows up in aligned data. Take a line reading name→age→role with tabs between the fields: blind replacement produces ragged columns, because name and age are different lengths. This converter computes the real distance to the next tab stop, so columns that lined up before still line up afterwards.

Going the other way

Converting spaces back to tabs only touches leading whitespace. This is deliberate. Spaces inside a line are usually meaningful — they are part of a sentence, a string literal, or a deliberate alignment — and converting them to tabs would corrupt the content. Indentation is the part you actually want tab-ified, so that is the only part that changes.

Why this keeps coming up

  • Python. Mixing tabs and spaces in the same block is a TabError in Python 3. Since the two look identical on screen, the fastest fix is to convert the whole file one way and move on.
  • YAML. Tab characters are not permitted for indentation at all. A single tab pasted in from elsewhere breaks the entire document, usually with an error pointing somewhere unhelpful.
  • Makefiles. The opposite rule: recipe lines must start with a real tab. An editor that helpfully converted your tabs to spaces produces the famous "missing separator" error.
  • Team style rules. Most linters enforce one or the other. Converting before you commit avoids a diff full of whitespace-only changes.

Which should you use? There is no universal answer, but there is a useful tiebreaker: tabs let each reader choose their own indent width, which is a genuine accessibility benefit for developers who need large indentation to track nesting. Spaces guarantee that alignment looks identical everywhere. Pick whichever your project already uses and stay consistent.

Frequently asked questions

What tab width should I use?

Four is the most common default and what most editors assume. Python's style guide specifies four spaces; Go uses tabs; many JavaScript projects use two. If your project has a linter configuration, match it.

Will this break alignment in my tables?

No. Tabs are expanded to the next tab stop rather than replaced with a fixed number of spaces, so tab-separated columns stay aligned after conversion.

Why does spaces-to-tabs only change the start of the line?

Because spaces inside a line are usually part of the content — words in a sentence, or a string literal. Converting those to tabs would change your data, so only leading indentation is touched.

Can I convert a tab-separated file to something else?

For TSV data, use the CSV-to-JSON tool and set the delimiter to a tab. This converter is for indentation rather than data conversion.