Convert Spaces to Tabs Online — Fix Indentation Fast — Free
Runs 100% in your browser — your files never leave your device.
When your editor wants tabs but the code arrived indented with spaces, reindenting by hand invites mistakes. Paste the code, choose the tab width — 2, 4, or 8 spaces per tab — and the leading spaces are rewritten as tabs, with any remainder left as spaces. Only indentation is touched; spaces inside lines stay put. Processing stays in your browser.
How it works
- 1
Paste your code or text
Space-indented content works best.
- 2
Choose the tab width
Pick how many leading spaces equal one tab: 2, 4, or 8.
- 3
Copy the tab-indented result
The converted text appears live and copies with one click.
About this tool
Why convert to tabs
Tabs let every developer choose their own indent width — two spaces on one screen, eight on another — from the same file. Teams standardized on spaces for consistency, but tab-preferred editors and some formats still want real tab characters.
How the conversion works
The tool replaces runs of your chosen space count with single tab characters, reading the leading whitespace of each line. Lines indented by a different width than your setting pass through untouched rather than mis-converted.
Going the other way
Most modern style guides prefer the opposite direction — the tabs-to-spaces converter freezes alignment for every viewer. Convert spaces to tabs only when a format or team convention explicitly calls for tabs.
Frequently asked questions
What space count should I treat as one tab?
Match the file's existing rhythm: if the code indents in 4-space steps, one tab per 4 spaces. Wrong widths leave the file half-converted.
Do spaces in the middle of a line convert too?
Only leading indentation converts — spaces inside the text stay as written, which keeps aligned comments and inline formatting intact.
Why do teams prefer spaces at all?
Spaces render identically in every editor, terminal, and diff view. Tabs are more flexible per developer; spaces are more predictable per file — both are defensible, which is why the debate never ends.