How to use the tabs to spaces converter
- Paste your text or code into the first box. Tabs in pasted text are kept.
- Choose Tabs to spaces or Spaces to tabs, and set the spaces per tab from 1 to 16.
- Tick Only indentation at line start if tabs or spaces inside the text should be left alone.
- Read the converted text in the result box and Copy converted text or Download file.
Tab stops, not a fixed number of spaces
A tab does not mean a fixed number of spaces. It moves to the next tab stop, a multiple of the width, so a tab after three characters at width 4 adds just one space, while a tab at the start of a line adds four. Tabs to spaces here follows tab stops the same way a text editor does, so columns line up as they did on screen.
For example, ab, tab, c, tab, d at width 4 becomes ab, two spaces, c, three spaces, d. Switch on the indentation-only option and tabs inside the text stay as they are.
Spaces to tabs
Going the other way, only the spaces at the start of a line are changed, in whole groups of the width. Eight spaces at width 4 become two tabs, and six spaces become one tab and two spaces. Spaces inside a line are never touched, because turning those into tabs would change how the text looks and break strings and aligned columns.
If you convert indentation in one direction and then back at the same width, you get the original, as long as the original used only tabs or only complete groups of spaces.
Why it matters
Mixed tabs and spaces cause odd alignment when the same file is viewed with different tab widths, and some formats such as YAML and Python are picky about indentation. Many teams pick one style and convert the rest. See also the CSS formatter, the JSON formatter and the text cleanup tool.
Everything runs in your browser and nothing is uploaded. The limit is 500,000 characters. Windows line breaks are turned into plain line breaks in the output.
Assumptions and limits
- The width is a whole number from 1 to 16, and tab stops are counted from the start of each line.
- Characters are counted as code points, so wide characters and emoji count as one column.
- Spaces to tabs affects only leading spaces and leaves a remainder of fewer spaces than the width.
- Nothing is uploaded or stored, and the input is limited to 500,000 characters.
Frequently asked questions
How do I convert tabs to spaces?
Paste the text, leave Convert on Tabs to spaces and set the width. Every tab moves to the next tab stop, the way an editor shows it.
Why does one tab give fewer spaces than the width?
Because a tab goes to the next multiple of the width. After three characters at width 4, only one space is needed to reach the next stop.
Can I convert spaces back to tabs?
Yes. Choose Spaces to tabs. Leading spaces become tabs in whole groups of the width, and spaces inside text are not changed.
Will it change spaces inside my sentences?
No. Spaces to tabs works only on the indentation at the start of each line, and Tabs to spaces can be limited the same way with the indentation-only option.