Convert Tabs to Spaces
Number of spaces per tab:
How to use Convert Tabs to Spaces
- 1
Paste your text
Paste code or text that contains tab characters into the input box.
- 2
Set spaces per tab
Choose how many spaces each tab should become using the 'Number of spaces per tab' field, such as 2 or 4.
- 3
Convert the tabs
Click 'Convert Tabs to Spaces' and every tab is replaced by your chosen number of spaces.
- 4
Copy the output
Use 'Copy Output' to grab the cleaned, space-indented text for your editor or document.
Converting Tabs to Spaces for Consistent Indentation
What the tool does
This tool replaces every tab character in your text with a number of spaces that you choose. Set the spaces-per-tab field to 2, 4, or any value, and each tab becomes exactly that many spaces. The replacement is literal and one-to-one: one tab in, your chosen count of spaces out.
Because a tab is a single invisible character that an editor renders at some display width, swapping it for a fixed number of real spaces makes the indentation concrete and identical everywhere the text is viewed.
Why tabs and spaces cause trouble
A tab does not have a fixed width; it is a signal that means advance to the next tab stop. Different editors and viewers set those stops differently, commonly at 2, 4, or 8 columns. The same tab-indented file therefore looks neatly aligned in one editor and ragged in another, which is the root of the long-running tabs-versus-spaces debate.
Spaces, by contrast, are unambiguous. A run of four spaces is four columns wide no matter where you open the file. Converting tabs to spaces trades the flexibility of tabs for guaranteed, portable consistency.
Choosing your tab width
The number you pick should match the convention of wherever the code is going. Many JavaScript and TypeScript projects use 2 spaces. Python's widely followed style guide specifies 4. Some C and Go codebases historically used the equivalent of 8. Before converting, check the project's style guide or existing files so your spaces line up with everyone else's.
If you get the count wrong, your converted code will still be valid but its indentation depth will not match the surrounding code, which looks jarring in review. It is worth confirming the right width up front.
Every tab, not just indentation
This tool replaces all tab characters in the text, including any that appear in the middle of a line, not only the leading indentation at the start of each line. That is usually what you want, since stray mid-line tabs are exactly the kind of inconsistent whitespace that causes misalignment.
Keep it in mind for tab-separated data, though: if a line uses tabs as column delimiters, converting them to spaces will change how that data is parsed. For source code indentation this is the correct behavior; for TSV data it may not be.
Languages where it really matters
In Python, indentation is part of the syntax, and mixing tabs and spaces in the same block is an error the interpreter will reject. Normalizing everything to spaces removes a whole class of confusing failures. YAML is similarly strict and disallows tabs for indentation entirely, so converting tabs to spaces is often mandatory to make a YAML file valid.
Even in languages where indentation is cosmetic, consistent spaces keep diffs clean and prevent the alignment from shifting when a teammate opens the file with different tab settings.
Line breaks and other whitespace are safe
The conversion is scoped to tab characters only. Your line breaks, your existing spaces, and the rest of your content are left exactly as they were. Nothing is merged, trimmed, or rearranged beyond turning each tab into spaces. This makes the tool safe to run on a whole file without worrying it will disturb the structure.
If you find your code also has runs of extra spaces you want collapsed, that is a separate job for a whitespace cleanup tool; this one stays focused on the tab-to-space substitution.
Fitting it into your workflow
A typical use is pasting a snippet copied from a source that used tabs into a project that requires spaces, converting it to the project's width, and dropping it in already correctly indented. It is also handy for one-off cleanups when an editor's auto-formatter is not set up or available.
Since the whole thing runs in your browser with no upload, you can safely convert proprietary or sensitive code, and the result is instant, so you can try different widths and compare until the indentation matches.
Frequently asked questions
How many spaces does each tab get converted to?
Why convert tabs to spaces in code?
Does it only replace leading indentation or all tabs?
Will it change my line breaks or other whitespace?
Is it free and is my code uploaded anywhere?
Related tools
Keep going with these handy tools