About this tool
Converts tabs to spaces and spaces back to tabs using real tab stops, so mid-line alignment survives the change.
A tab to spaces converter replaces tab characters with the spaces that actually reach the next tab stop, rather than blindly swapping every tab for a fixed number of spaces. Tab stops sit at every multiple of the tab size, so with a size of 4 a tab at column 0 becomes four spaces but a tab at column 6 becomes two — the rule POSIX `expand` follows, and the reason naive converters wreck aligned comments. The tool also runs the conversion backwards like `unexpand`, detects what the file currently uses, and can normalise line endings and trailing whitespace at the same time.
Open Tab to Spaces Converter on AltFTool — it loads instantly in your browser.
Paste or upload your source content.
Choose the target format or conversion mode.
Copy or download the converted result.
Column position is tracked character by character, so a mid-line tab expands to the right width instead of a fixed count.
Before converting, it reports whether the file is tab-indented, space-indented or mixed, and guesses the indent width.
Spaces-to-tabs touches only leading indentation unless you ask for more, so runs of spaces inside strings are left alone.
It depends on where the tab sits. A tab moves to the next tab stop, and tab stops are at every multiple of the tab size — so with tab size 4, a tab at column 0 produces 4 spaces, at column 1 produces 3, and at column 6 produces 2. The formula is tabSize − (column mod tabSize). Only a tab that starts exactly on a tab stop produces a full tabSize of spaces.
It depends on the language and the project. Go requires tabs and gofmt enforces them; Makefiles require a literal tab to begin a recipe line; Python allows either but forbids mixing them in one file, and PEP 8 recommends 4 spaces. The one rule that always holds is consistency within a file, because mixed indentation is what actually causes broken diffs and syntax errors.
Not with the default setting, which converts leading indentation only — the same behaviour as POSIX `unexpand` with no flags. Turning that off converts every run of two or more spaces anywhere on the line, matching `unexpand -a`, and that can rewrite spaces inside string literals and aligned comments. Use it only on files you can re-check.
Because one tab byte becomes up to tabSize space bytes. A file with 1,000 tabs converted at tab size 4 gains up to 3,000 bytes. That is normal and is why some projects prefer tabs. The tool shows the before and after byte counts so you can see exactly what the change costs.
Add the Tab to Spaces Converterwidget to your blog or website — free, responsive, no signup. Just keep the “Widget by AltFTool” credit link visible.
<iframe src="https://www.altftool.com/embed/widget/tab-to-spaces-converter"
title="Tab to Spaces Converter — free AltFTool widget"
width="100%" height="640" style="border:0;border-radius:12px;overflow:hidden"
loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe>
<p style="font-size:12px;margin:4px 0 0">Widget by <a href="https://www.altftool.com/tools/all/tab-to-spaces-converter?utm_source=embed&utm_medium=widget">AltFTool — free online tools</a></p>