Space to Tab Converter

Convert spaces to tabs online. Replace groups of spaces with tab characters, set a custom tab width, convert only the leading indentation spaces, or use smart tab stops to rebuild tabs at true column boundaries — the exact inverse of converting tabs to spaces.


    
Options
0 Spaces found
0 Tabs created

ToolsSoup's Space to Tab Converter is a free online tool that turns runs of spaces in your text or code back into tab characters in one click. Set how many spaces make up one tab, keep the change to the leading indentation spaces, or switch on smart tab stops so the tabs land exactly on the column boundaries an editor would use. It's the quickest way to convert space-indented code to tabs when a project's style guide requires tabs, when you prefer tabs for accessibility and adjustable width, or when you need to undo a tabs-to-spaces conversion. The converted text appears next to a count of how many spaces were found and how many tabs were created, ready to copy. Everything runs in your browser — no uploads, no sign-up, and your text never leaves your device.

What is a space to tab converter?

A space to tab converter replaces groups of space characters in a piece of text or source code with tab characters. It's the reverse of a tab-to-space conversion: where one tool expands each tab into a fixed number of spaces, this one collapses each fixed-width group of spaces back into a single tab. Because a tab is a single character that an editor can display at any width, switching from spaces to tabs lets every reader choose their own indentation size — two columns, four, eight — without changing the file. This tool lets you pick the number of spaces per tab and optionally use smart tab stops, which place tabs at the column boundaries an editor expands them to instead of simply chunking every N spaces.

How to convert spaces to tabs

Converting spaces with ToolsSoup takes only a few seconds:

  1. Type or paste the text or code that uses spaces for indentation into the first box.
  2. Set the spaces per tab (2 and 4 are the most common), and optionally turn on smart tab stops or convert all spaces instead of just the leading indentation.
  3. Click Convert spaces to tabs, check how many tabs were created, then click Copy result to grab the tab-indented text.

Leading spaces vs. all spaces

By default the converter only touches the leading whitespace of each line — the indentation — and leaves spaces inside the line untouched, so words and sentences keep their normal single spacing. That's the safe choice for source code, where only indentation should become tabs. Turn on Convert all spaces and the tool processes the whole line, collapsing every qualifying run of spaces into tabs; combine it with smart tab stops when you're rebuilding column-aligned data. For ordinary prose, leave Convert all spaces off so the spaces between words are preserved.

Why convert spaces to tabs?

Some teams and languages prefer tabs over spaces: a single tab is one keystroke and one byte, it lets each developer view indentation at the width they like, and it is increasingly recommended for accessibility because readers using screen magnifiers or braille displays can adjust tab width. Languages like Go and Makefiles expect tabs outright. Converting space indentation to tabs before committing keeps a codebase consistent with a tabs-based style guide and reverses an accidental tabs-to-spaces change without retyping anything.

Why use this space to tab converter?

  • Collapse each fixed-width group of spaces into a single tab character.
  • Choose how many spaces make up one tab to match your project's style.
  • Convert only the leading indentation by default, leaving in-line spaces intact.
  • Use smart tab stops to rebuild tabs at real column boundaries like an editor.
  • See how many spaces were found and how many tabs were created at a glance.
  • Result is ready to copy with a single click.
  • Runs entirely in your browser — your text is never uploaded.

Frequently asked questions

How many spaces equal one tab?

That depends on your project's convention. Four spaces per tab is the most common, while many JavaScript and web projects use two. Set Spaces per tab to match how the file was originally indented so each group of that many spaces becomes exactly one tab.

Will it change the spaces between words?

Not by default. The converter only touches the leading indentation of each line, so the single spaces between words stay as they are. If you specifically want to convert spaces throughout the line, turn on Convert all spaces.

What do smart tab stops do?

With smart tab stops on, tabs are placed at the column boundaries an editor would expand them to — the next multiple of your tab width — instead of simply replacing every N spaces. This reproduces an editor's exact tab positions and is useful when rebuilding column-aligned text.

What happens to leftover spaces?

If a run of spaces isn't an exact multiple of the tab width, the extra spaces that don't fill a whole tab are left in place as spaces. For example, with a width of 4, six leading spaces become one tab followed by two spaces.

Does it convert tabs back into spaces?

No — this tool only turns spaces into tabs. To go the other way and expand tabs into spaces, use the Tab to Space converter.

Is my text private?

Absolutely. All conversion happens locally in your browser using JavaScript, so the text you enter is never sent to or stored on any server.