Boneyard Tools

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

  1. Paste your code into the input box.
  2. Pick the direction: tabs to spaces or spaces to tabs.
  3. Set the tab width (how many columns a tab spans).
  4. 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 1
def 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