Free tool

Tabs to Spaces Converter

Convert your code's indentation between tabs and spaces instantly. 100% in your browser.

Built by

Miguel Ángel Colorado Marin (MACM)

Full-Stack Developer · Guadalajara, España

I develop web apps, digital tools and full projects — from design to deployment.

Contact me

This tool converts a code block's indentation between tabs and spaces, useful when you switch editors, follow a new team style standard or prefer one indentation type over the other. Paste your code, choose the conversion direction (tabs to spaces or spaces to tabs) and the width (2, 3, 4 or 8 spaces per level, or a custom value), and the result is generated instantly, ready to copy. All processing happens with JavaScript directly in your browser.

Features

  • ✓Tabs to spaces and spaces to tabs
  • ✓Indentation width 2, 3, 4 or 8, or a custom value
  • ✓Instant conversion as you type
  • ✓Copy to clipboard with one click
  • ✓100% in browser, no uploads

How to convert tabs to spaces?

  1. 1

    Paste your code

    Type or paste the code in the box on the left.

  2. 2

    Choose the direction

    Tabs → Spaces or Spaces → Tabs.

  3. 3

    Choose the width

    2, 3, 4 or 8 spaces per indentation level, or a custom value in the number field.

  4. 4

    Copy the result

    The converted code appears instantly, ready to copy.

How each conversion is calculated

The conversion works line by line on the leading indentation, meaning the spaces and tabs before the first character of each line. A tab is not a fixed number of spaces: it advances to the next multiple of the chosen width, as in an editor. With width 4, “two spaces and a tab” fill 4 columns and become 4 spaces, while “a tab and two spaces” become 6. With width 2, two consecutive tabs give 4 spaces.

In the reverse direction the rule is fixed and does not use tab stops: each complete block of as many spaces as the width is replaced by one tab, and leftover spaces are kept. With width 4, ten leading spaces become two tabs and two spaces. With width 2, five spaces become two tabs and one space. A line that starts with a tab is left unchanged even if spaces follow it, because this direction only looks at leading spaces.

A practical case: if your editor displays tabs as 4 columns and the code arrived with tabs, choose width 4 so the resulting space indentation matches what you were seeing. With width 2, each level takes half as many spaces.

What is kept and what is not

The browser's text field works with LF line endings, so a Windows file pasted with CRLF comes out with LF. Nothing outside the indentation is touched: alignment tabs in the middle of a line, such as the ones separating code and a comment, and trailing spaces stay as they are. The result is recalculated as you type, and the Copy button takes the whole block to the clipboard.

There are limits to know about. The tool does not detect the language or read settings such as .editorconfig, so you choose the width yourself. Because it works line by line and does not parse the syntax, it also changes indentation inside multi-line strings, template literals or embedded text blocks. If that indentation is part of the content, review it after converting.

All processing is local, with JavaScript in your browser. The code you paste is not sent to any server or stored between visits, and the result field is read-only, so what you copy is exactly what is shown.

Frequently asked questions

Is my code uploaded to a server?

No. Everything is processed with JavaScript directly in your browser.

What indentation width should I use?

It depends on your project. The tool does not detect the width of your code: choose it based on your editor settings, your linter or your .editorconfig file.

Does it respect the rest of the code, not just the indentation?

Yes. It only modifies the tabs or spaces at the start of each line. Alignment tabs inside a line and trailing spaces stay intact, and line breaks too, except CRLF, which the browser's text field converts to LF.

Related tools

Embed Tabs to Spaces Converter on your site

Add Tabs to Spaces Converter to any web page with a simple iframe. Free, with attribution to miguelacm.es.

<iframe
  src="https://miguelacm.es/embed/tabs-spaces-converter?locale=en"
  width="100%"
  height="700"
  frameborder="0"
  allow="clipboard-write"
  title="Tabs to Spaces Converter — miguelacm.es"
></iframe>
View embed in new tab →