My Tool Studio
Text

Tabs to Spaces Converter

Paste code or tab-separated text and this tool will convert tabs to spaces at the width you choose, or turn leading spaces back into tabs. Tabs to spaces uses real tab stops by default, the way the Unix expand command does, so a tab pads out to the next multiple of the width and columns stay lined up. You can also convert only the indentation at the start of each line and leave tabs inside lines alone. Spaces to tabs touches only leading indentation by default, or also aligned spaces inside lines, like unexpand -a. You can remove trailing whitespace and view the result with visible spaces and tabs. Set the width from 1 to 8, or click 2, 4 or 8. It helps with whitespace noise in pull requests and YAML files that refuse tabs. It runs in your browser.

Always freeNo sign upRuns in your browser

How to use

01

Set the tab width

Type a number from 1 to 8 in Tab width, or click 2, 4 or 8. Match your project's style: 4 is standard for Python, and 2 is common in JavaScript and YAML.

02

Pick a direction and options

Click Tabs to spaces or Spaces to tabs and set the options for that direction. Tick Remove trailing spaces and tabs or Show whitespace in the result if you need them.

03

Paste and copy

Paste your text into Input, open a file, or press Try sample to load a Python function and a small table. Copy or download the converted text.

Why Tabs to Spaces Converter

Tabs or spaces: common language defaults

Most languages leave the choice to the team, but a few have firm rules or strong conventions. When in doubt, follow the formatter the project already uses. Many projects also include an .editorconfig file that sets indent_style and indent_size, and many editors follow it, some through a plugin.

Language or fileIndentationNotes
Python4 spacesRecommended by PEP 8. Mixing tabs and spaces ambiguously is an error in Python 3.
GoTabsgofmt, the standard formatter, indents with tabs.
JavaScript and TypeScript2 spaces is commonPrettier's default is 2 spaces; some teams use 4.
YAMLSpaces onlyTabs are not allowed for indentation.
MakefileTab before each recipe lineSpaces cause a missing separator error.
HTML and CSS2 spaces is commonNo rule; follow the project's formatter.

Common questions

What does Align to tab stops do when converting tabs to spaces?
Each tab is replaced by however many spaces it takes to reach the next multiple of the tab width. With width 4, a tab after a 10-letter word adds 2 spaces, while a tab at the start of a line adds 4. Untick it to replace every tab with exactly the width in spaces.
Does converting tabs to spaces change tabs in the middle of a line?
By default, yes, every tab is converted. Tick Leading indentation only to convert just the tabs at the start of each line. That keeps tabs inside strings and between TSV fields untouched.
How does Spaces to tabs decide which spaces become tabs?
By default it only looks at the indentation at the start of each line. That indentation is measured in columns, turned into as many tabs as fit, and any leftover columns stay as spaces. Tick Also convert aligned spaces inside lines and a run of two or more spaces that ends on a tab stop becomes a tab anywhere in the line, the way unexpand -a works.
What tab width should I use to convert tabs to spaces in Python?
Four spaces, which is what the PEP 8 style guide recommends. Python 3 refuses to run code that mixes tabs and spaces in a way that makes the indentation ambiguous, so converting a whole file to spaces is the safe fix.
Can YAML files use tabs for indentation?
No. The YAML specification does not allow tab characters for indentation, and parsers report an error when they find one. Convert tabs to spaces, usually 2 per level, before saving.
Will converting a Makefile's tabs to spaces break it?
Yes. Make requires recipe lines to start with a real tab character, and a version with spaces fails with a missing separator error. Keep Makefiles out of the tabs to spaces direction.
Can I line up a tab-separated table by expanding its tabs?
Often, yes. With Align to tab stops on, each field starts at the next tab stop, so columns line up as long as no value is wider than the tab width. A long value pushes its row out of line, so pick a larger width for wide data.
How can I see where the tabs and spaces are in the converted text?
Tick Show whitespace in the result. A panel below the output shows every space as a middle dot and every tab as an arrow, so mixed indentation and trailing spaces are easy to spot. The copied text is not changed by this view.
Does the converter change anything except tabs and spaces?
No. Letters, symbols and line breaks pass through unchanged. Wide characters such as emoji or Chinese characters count as one column, so alignment after them can look off in some fonts.

More Text tools

View all