Tabs to Spaces Converter

Convert tab characters to spaces, or turn leading spaces back into tabs, with the width you choose. Makes mixed indentation in code and logs consistent.

Mixed tabs and spaces are one of the oldest annoyances in text. A file looks perfectly aligned in one editor and ragged in another, because a tab is not a fixed width: it jumps to the next tab stop, and different programs set that stop at two, four or eight characters. Spaces are always one character wide, which is why many style guides prefer them.

This tool converts in either direction. Choose the direction, set the width, and paste your text.

Tabs to spaces

Every tab character is replaced by the number of spaces you set, which defaults to four. Two is common in JavaScript, HTML and YAML projects; four in Python, Java and C#; eight if you want to reproduce the traditional terminal look.

One honest limitation: this replaces each tab with a fixed run of spaces, which is exactly right for leading indentation but can misalign columns in the middle of a line. A real tab only advances to the next stop, so a tab after three characters in a four-wide setting would be one space, not four. If your text is a table with tabs between columns, line it up in a spreadsheet instead.

Spaces to tabs

The other direction looks only at the indent at the start of each line. Groups of spaces equal to your tab width become one tab, and anything left over stays as spaces. With a width of four, an eight-space indent becomes two tabs, and a six-space indent becomes one tab and two spaces. Spaces in the middle of lines are never touched, which protects aligned comments and string contents.

Things to check before committing

If a project uses a formatter like Prettier, Black or gofmt, let that do the job and treat this tool as a one-off for snippets. Never run a conversion over a file that is whitespace-sensitive in a way you do not control. Makefiles require real tabs before commands, and converting them to spaces breaks the build. YAML refuses tabs for indentation entirely, so going the other way there is a good fix.

Plain text, logs and pasted terminal output are the happy cases, since they have no rules to break.

Alongside other tools

If a pasted block has indentation you do not want at all, remove extra spaces trims the start of every line. To number the lines of a snippet for a bug report or a lesson, add line numbers, and to fit long lines into a width, use the text wrapper.

Frequently asked questions

Why does my table still look wrong after converting tabs to spaces?

Tabs in the middle of a line jump to the next tab stop, not a fixed distance, so a fixed number of spaces cannot reproduce them. For tables, open the data in a spreadsheet or use a fixed-width layout.

What width should I choose?

The one your project uses. Four is the most common default; two is typical for web code and YAML. If you are not sure, four is a safe choice for plain text.

Will it convert tabs inside strings and comments in my code?

Tabs to spaces replaces every tab, wherever it is. Spaces to tabs changes only leading indentation.