Tab and Space Converter
Switch indentation between tabs and spaces without breaking the layout. The converter works with real tab stops, so a tab after some text moves to the next stop exactly as an editor would show it, and spaces are only turned into tabs where they line up with a stop.
Convert Tabs and Spaces
Converted text
Changes
How to Use the Tab and Space Converter
- Paste your text or code.
- Choose the direction and the tab width your editor uses.
- Choose whether to convert only the indentation at the start of each line (safest for code) or every tab or run of spaces.
- Copy or download the converted text.
About This Tool
Developers matching a project's indentation style, people pasting code into a forum or document that mangles tabs, and anyone cleaning up a mix of tabs and spaces.
Input: Plain text or code · Output: Plain text or code.
Features and Limitations
Features
- Column-aware: tabs expand to the next tab stop, not a fixed number of spaces.
- Spaces to tabs uses tabs only where whole tab stops are filled and keeps leftover spaces.
- Leading-only mode leaves tabs and spaces inside strings and comments untouched.
- Shows how many lines changed.
Limitations
- In “everywhere” mode, spaces inside string literals can be turned into tabs, which may change program output; use leading-only for code.
- Width is counted in characters, so wide characters such as Chinese letters or emoji can make alignment look off.
- Single spaces are never converted to a tab in “everywhere” mode, to avoid changing ordinary word spacing.
- Results are computed in your browser; nothing you enter is sent to a server.
Example
With a tab width of 4, “\tif (x)” becomes “ if (x)”, and “a\tb” becomes “a b” because the tab after one character only needs three spaces to reach the next stop.
Frequently Asked Questions
What is a tab stop?
Tab stops are fixed columns, every 4 characters for a tab width of 4. A tab moves the cursor to the next stop, so its width depends on where it starts.
Should I convert only leading indentation?
Yes for code. Indentation is where tabs and spaces matter; converting inside lines can alter strings or alignment in comments.
Why were some spaces not turned into tabs?
Spaces become a tab only if they reach a tab stop. Two spaces in the middle of a stop, or leftover spaces after the last stop, stay as spaces.
Which tab width should I choose?
Use the width your editor or project uses. Python and JavaScript projects commonly use 4, some style guides use 2, and many terminals show tabs as 8.
Related Tools
More like this: all Case & Formatting tools, all Text & Writing tools or the TinySandy home page.