How to use Tab to Spaces
- Paste your text or code into Your text. The sample is a small function indented with tabs.
- Pick Spaces per tab: 2, 4 or 8. The default is 4.
- Tick Align to tab stops (like an editor) if tabs appear in the middle of lines and you want columns to stay aligned.
- Copy the result. It is shown in a monospaced font so you can check the alignment.
What it does and when to use it
A tab is one character, but different programs show it at different widths. Code indented with tabs can look neat in one editor and staggered in another, in an email or on a web page. Converting tabs to spaces fixes the look everywhere.
Common reasons to convert:
- a style guide or linter requires spaces;
- you are pasting code into a forum, chat, document or slide where tabs show too wide;
- YAML files, which do not allow tabs for indentation;
- tab-separated data that you want to read as aligned plain-text columns.
Fixed replacement (the default) is right for indentation at the start of lines, because there every tab should become the same amount of space. Tab stops are right for tabs after text. A word of 2 letters and a word of 9 letters followed by a tab both reach the same column, just as in a code editor.
After converting, Trim Lines can remove trailing spaces, and Text Padder can widen columns further. To squeeze runs of spaces inside lines, use Remove Extra Spaces.
How it works
In fixed mode, every tab character in the text is replaced with the chosen number of spaces. That is all.
In tab-stop mode, the tool walks along each line keeping track of the column. Ordinary characters move it forward by 1. At a tab, it inserts size − (column mod size) spaces, which lands exactly on the next multiple of the size. The column restarts at 0 on each new line. It all happens in your browser.
Worked examples
Two-space indent. A three-line block with return 1; indented by one tab, at 2 spaces per tab, comes out with return 1; indented by two spaces.
Columns with tab stops. “Name”, “Jo” and “Alexandra”, each followed by a tab and a value, at size 8 with tab stops. “Name” (4 letters) gets 4 spaces and “Jo” gets 6, so “Age” and “31” both start at column 8. “Alexandra” (9 letters) passes the first stop, so it gets 7 spaces to reach column 16.
Same columns without tab stops. Each tab becomes 8 spaces regardless of position, giving Name Age with 8 spaces, and the values no longer line up.
Limits and tips
- Tab stops count each visible character as one column. Wide characters such as emoji or Chinese characters can still make columns look uneven.
Frequently asked questions
Should I use 2, 4 or 8 spaces?
What does "Align to tab stops" change?
Does it touch spaces that are already there?
How do I go back from spaces to tabs?
How do we know nothing is uploaded? Test it yourself on the privacy proof page.