Tabs to Spaces Converter
Paste code or text, choose the tab width, and change every tab to the right number of spaces, or change indentation made of spaces into tabs.
Worked examples
Tabs to spaces with stops
ab c indented
ab c indented
The tab after ab fills two spaces to reach the stop at column 4.
Spaces to tabs
one two
one two
Four spaces become one tab.
About Tabs to Spaces Converter
A tab is not the same as a fixed number of spaces. It moves the text to the next tab stop, so a tab after two letters fills only two spaces when stops are four apart, while a tab at the start of a line fills four. Replacing every tab with the same number of spaces therefore misaligns columns. This converter works out each tab's width from the column it sits in, so aligned text stays aligned.
Choose the tab width, usually 2, 4 or 8 to match your editor, and convert tabs to spaces. You can also go the other way: the spaces at the start of each line are turned into tabs, in whole tab widths with any remainder left as spaces. Spaces in the middle of a line are never changed, so text and aligned columns are kept. Line endings and everything else stay as typed.
How to use Tabs to Spaces Converter
- Paste your text or code into the box.
- Choose tabs to spaces, or leading spaces to tabs.
- Set the tab width.
- Copy the converted text.
Common uses
- Making code indent the same way in every editor
- Cleaning up text pasted from a spreadsheet or a terminal
- Meeting a style guide that requires spaces or tabs
- Fixing the layout of a plain text table
Frequently asked questions
Why not just replace each tab with four spaces?
Because tabs align to stops. A tab after two characters only needs two spaces to reach the next stop at column four, and a fixed replacement would push the following text out of line.
Which tab width should I choose?
Use the width your editor or style guide uses, most often 4, but 2 and 8 are common too.
Does converting to tabs touch spaces inside a line?
No. Only the spaces and tabs at the very start of each line are changed.
What about files that must use spaces?
Languages such as Python and formats such as YAML are happiest with spaces, so convert tabs to spaces before sharing them.