Convert Tabs to Spaces (and Spaces to Tabs)
Paste code or text to switch its indentation between tabs and spaces. Choose the tab width and whether to convert just the leading indent or whitespace everywhere. Tabs are expanded and packed using real tab stops, so alignment is preserved.
How to convert tabs to spaces
- Paste your code into the input box.
- Pick the direction: tabs to spaces or spaces to tabs.
- Set the tab width (how many columns a tab spans).
- Copy the reindented result.
Examples
Tabs to 2 spaces
function f() {
return 1;
}function f() {
return 1;
}4 spaces to a tab
def f():
return 1def f(): return 1
Frequently asked questions
What does tab width do?
It sets how many columns a tab spans. A tab advances to the next multiple of the tab width, so one tab with width 4 fills columns up to the next stop at 4, 8, 12 and so on. This keeps indentation aligned rather than swapping a fixed number of characters.
What is the difference between leading and all scope?
Leading scope only changes the indentation at the start of each line and leaves whitespace inside the line alone, which is the safe default for code. All scope converts whitespace anywhere in the line, matching how the unexpand tool with -a works.
Does converting spaces to tabs break alignment?
No. Leading spaces are measured as a visual width, then rebuilt as whole tabs plus any leftover spaces, so the indentation lands on the same column. Single spaces between words are never turned into tabs.
Are Windows and Mac line endings preserved?
Yes. CRLF, CR and LF line endings are all kept exactly as they were, including blank lines and a trailing newline.
Why are some spaces left after a tab when converting to tabs?
A tab can only reach the next tab stop. If the indentation is not a clean multiple of the tab width, the remainder stays as spaces so the visual column does not change.
Is my code private?
Yes. Everything runs in your browser and nothing is uploaded.
Related tools
CSS Formatter
Beautify and format messy or minified CSS online. Indent rules, put one declaration per line and tidy spacing. Runs in your browser.
JSON Formatter
Format, validate and minify JSON online. Pretty-print with custom indentation, sort keys and catch syntax errors. Runs in your browser.
Remove Extra Spaces
Remove extra spaces from text online. Collapse double spaces and tabs to one, trim every line, drop blank lines, then copy or download. Free and private.
Whitespace Remover
Remove extra whitespace from text online. Collapse double spaces, strip all spaces and tabs, trim lines, and drop blank lines. Free, private, instant.
.env to JSON
Convert a .env file to JSON, or JSON back to .env. Parses KEY=value lines, comments, quotes and export. Runs entirely in your browser.
ASCII Table
Full ASCII table for all 128 codes with decimal, hex, octal and binary values, character names and descriptions. Search by code, hex or character.