Tabs to Spaces
Convert tab characters to spaces
What Is the Tabs to Spaces Tool?
The Tabs to Spaces tool replaces every tab character in your text with a specified number of spaces, which is the conversion direction you need when moving code or formatted content into an environment that handles spaces but renders tabs inconsistently or not at all. Paste your content in, click Convert Tabs to Spaces, and the substitution runs across the whole block. It is the counterpart to the Spaces to Tabs tool and the two come up together constantly when code moves between editors, systems, or style conventions that disagree on indentation.
Tab characters look fine in some environments and completely collapse in others, which makes this one of those conversions that seems minor until the formatting breaks somewhere it definitely should not.
How to Use This Tool
- Paste or type your text into the input box above.
- If a space count setting is available, set it to the number of spaces you want each tab replaced with. Common values are 2 or 4, depending on the indentation convention you are targeting.
- Click Convert Tabs to Spaces and every tab character in your input is replaced with the specified number of spaces.
- Copy the result using the Copy button, or select and copy manually. Use Clear to reset the input.
When Would You Use This?
Converting tab-indented code to space-indented code before pasting it into a project, editor, or codebase that enforces spaces and will flag tabs as a style violation in linting or formatting checks.
Fixing copied code or exported content that was tab-indented but is going into a web-based editor, a CMS, or a plain-text field that does not render tab characters correctly and shows them as a single narrow gap or nothing at all.
Preparing tab-separated data for a system or display that expects space-aligned columns, where tabs would either not align correctly or would be stripped out entirely during processing.
Examples
Converting tab-indented code to 4-space indentation
Input (tab used for indent):
function hello() {
console.log("hi");
}
Output (4 spaces per tab):
function hello() {
console.log("hi");
}
Converting to 2-space indentation
Input :
if (x) {
if (y) {
doSomething();
}
}
Output (2 spaces per tab):
if (x) {
if (y) {
doSomething();
}
}
Converting tab-separated columns to space-aligned
Input : Alice Manager London
Output (4 spaces per tab): Alice Manager London
Frequently Asked Questions
How do I convert tabs to spaces in a text file?
Paste the file contents into the input box and click Convert Tabs to Spaces. Copy the output and save it back to your file. The tabs are replaced with the number of spaces you specified.
How do I convert tabs to spaces in VS Code?
Open the file, go to the bottom status bar and click the indentation setting (it usually shows something like "Tab Size: 4"). Select "Convert Indentation to Spaces". VS Code applies the conversion to the current file. For text outside of VS Code, this tool handles it directly.
How do I convert tabs to spaces in Python?
Use the expandtabs() method: text.expandtabs(4) replaces each tab with spaces up to the next 4-character tab stop. For a flat replacement rather than tab-stop logic, use text.replace('t', ' '). For a quick manual conversion, paste into this tool.
How do I convert tabs to spaces in Notepad++?
Go to Edit, then Blank Operations, and select "TAB to Space". This replaces all tab characters with spaces. For text outside of Notepad++, paste into this tool instead.
How many spaces should replace a tab?
The most common values are 2 or 4. It depends on the coding convention of the project or language you are working in. Python projects often use 4, while some JavaScript or front-end projects use 2. Check the existing indentation in your target file if you are unsure.
Why do tabs cause formatting problems?
Tab characters render at different widths depending on the application and settings. In one editor a tab might be 4 characters wide, in another 8. That inconsistency makes tab-indented content look misaligned when it moves between environments. Spaces are always exactly one character wide, which is why many style guides prefer them.
What is the difference between a tab and spaces?
A tab is a single character (ASCII 9) that jumps to the next tab stop. Spaces are individual space characters (ASCII 32). They look similar in editors but are stored differently and treated differently by formatters, linters, and some web systems.
Can I choose how many spaces to use per tab?
Yes, if the tool provides a space count setting. Enter 2 for two-space indentation, 4 for four-space, or any other number that matches your target format.