Spaces to Tabs
Convert spaces to tab characters
What Is the Spaces to Tabs Tool?
The Spaces to Tabs tool converts consecutive space characters in your text into tab characters, which is the direction you need to go when code or structured text uses spaces for indentation but your target editor or system expects tabs. Paste your content in, click Convert Spaces to Tabs, and the substitution runs across the whole block at once. It is a direct counterpart to the Tabs to Spaces tool and the two come up together regularly when moving code between environments with different indentation conventions.
The spaces-versus-tabs debate in coding circles has been going on for decades and probably is not getting resolved anytime soon, but having a tool to convert between the two in seconds at least removes the practical friction of it.
How to Use This Tool
- Paste or type your text into the input box above.
- Check how many spaces represent one indent level in your source text. The tool converts that group of spaces into a single tab character. If a space count setting is available, set it to match your source indentation width, typically 2 or 4.
- Click Convert Spaces to Tabs and the conversion runs across every line in your input.
- Copy the result using the Copy button, or select and copy manually. Use Clear to reset the input.
When Would You Use This?
Converting space-indented code to tab-indented code before pasting it into an editor, project, or codebase that has a tabs-only convention and will flag spaces as a style violation.
Reformatting structured plain text or table content that uses spaces for alignment into a tab-separated format before importing it into a spreadsheet or database tool that uses tabs as the column delimiter.
Fixing exported code or copied snippets that came out of an environment that always uses spaces, before dropping them into a system where tabs are expected for proper indentation rendering.
Examples
Converting 4-space indentation to tabs
Input (4 spaces used for indent):
function hello() {
console.log("hi");
}
Output (tab used for indent):
function hello() {
console.log("hi");
}
Converting space-separated columns to tab-separated
Input : Alice Manager London
Output : Alice Manager London
(Tab-separated output ready for spreadsheet import)
Multi-level indentation converted
Input (2-space indent):
if (x) {
if (y) {
doSomething();
}
}
Output :
if (x) {
if (y) {
doSomething();
}
}
Frequently Asked Questions
How do I convert spaces to tabs in a text file?
Paste the file contents into the input box and click Convert Spaces to Tabs. Copy the output and save it back to your file.
How do I convert spaces to tabs in VS Code?
Go to the bottom status bar and click the indentation indicator (it usually shows "Spaces: 2" or similar). Select "Convert Indentation to Tabs". VS Code applies the conversion to the current file. For text outside of VS Code, this tool works without opening the editor.
How do I convert spaces to tabs in Notepad++?
Go to Edit, then Blank Operations, and select "Space to Tab (All)". This converts all leading spaces to tabs. For plain text outside of Notepad++, paste into this tool instead.
Why would I use tabs instead of spaces?
Tabs are a single character that editors can render at any visual width, which means developers can set their own preferred indent width without changing the file. Some languages like Python technically allow both but many codebases or style guides mandate one or the other for consistency.
How many spaces equal one tab?
It depends on your project's indentation convention. Common settings are 2 spaces or 4 spaces per indent level. Most editors let you configure the tab width separately from the indentation size. When converting, set the tool to match however many spaces your source uses per level.
How do I convert spaces to tabs in Python?
You can use the expandtabs() method in reverse by writing a manual replacement: text.replace(' ', 't') where the spaces match your indent width. For a quick no-code conversion, paste into this tool.
What is the difference between a tab character and spaces?
A tab is a single whitespace character (ASCII 9) that typically renders as a jump to the next tab stop. Spaces are individual space characters (ASCII 32). They look similar in most editors but are different characters and treated differently by code linters, formatters, and some file formats.
Does converting spaces to tabs affect non-indentation spaces?
Typically the conversion targets groups of spaces at the start of lines (indentation) rather than single spaces between words. Single spaces between words are usually left alone. Check the output if your content has unusual spacing patterns.