Skip to content

Tab to Space Converter

Convert tabs to spaces (or spaces back to tabs) in any text or code. Choose 2, 4, 8 or custom tab width. Free, private and no signup.

  • 100% free
  • No Signup
  • Runs in your browser
ADVERTISEMENT
Demo Ad 728 x 90 320 x 100

Convert tabs to spaces in 3 simple steps

  1. 1

    Paste

    Add your text, code or table data that contains tab characters.

  2. 2

    Choose tab width

    Pick 2, 4, 8 or a custom number of spaces per tab.

  3. 3

    Copy or download

    Copy the space-indented result or save it as a TXT file.

TAB TO SPACE CONVERTER GUIDE

Tab to Space Converter – Convert Tabs to Spaces (or Spaces to Tabs) Online Free

Need to replace tabs with spaces in your text or code? This free tab to space converter changes every tab character into the number of spaces you choose, and it can also convert spaces back into tabs. Paste your text, pick a tab width of 2, 4, 8 or a custom value, and the converted result appears at once. You can convert every tab in the text, or only the leading indentation at the start of each line, and you can turn on Align to tab stops for column aware conversion and Trim trailing spaces to tidy the end of lines. There is no signup and nothing to install.

Tabs and spaces look the same on screen, yet they behave differently. A tab is one character that each editor draws with its own width, so the same file can look neat in one program and broken in another. Spaces always have the same width, which is why many style guides, code formatters, markdown files, YAML files and plain text documents ask for spaces. This converter fixes mixed indentation in seconds. It runs in your browser, so your code and text are never uploaded or stored, and it keeps your line breaks and other characters unchanged.

Tabs to Spaces

Replace every tab, or only the indentation, with 2, 4, 8 or a custom number of spaces. Perfect for code, config files and copied tables.

Spaces to Tabs

Switch the other way and turn groups of spaces back into tabs when a project or tool requires tab indentation.

Align to Tab Stops

Use column aware conversion so text lines up as it would in an editor, instead of replacing each tab with a fixed number of spaces.

What Is a Tab to Space Converter?

A tab to space converter is an online tool that replaces the tab character (the invisible character you get when you press the Tab key) with regular space characters. Because a tab has no fixed width, programs show it as 2, 4 or 8 columns depending on their settings. Converting tabs to spaces makes the layout identical everywhere.

Developers search for this as convert tabs to spaces, replace tab with spaces, tab to 4 spaces or fix mixed indentation. Writers and data users need it too, for example when a table copied from a spreadsheet or a text file contains tab characters between columns.

How to Convert Tabs to Spaces Online (Step by Step)

Converting indentation takes a few seconds with our free tool.

  1. Add your text or code: Paste into the input box, or click Load sample to try the tool.
  2. Pick the direction: Choose Tabs to Spaces, or Spaces to Tabs if you want the reverse.
  3. Choose the tab width: Select 2, 4 or 8 spaces, or enter your own number.
  4. Decide where to convert: Convert every tab in the text, or only the leading indentation at the start of each line.
  5. Set options and copy: Turn on Align to tab stops or Trim trailing spaces if needed, then copy the result or download it as a TXT file.

To check the result afterward, you can compare the original and the converted text with the Text Diff Checker.

How Many Spaces Should Replace a Tab?

There is no single correct answer, because it depends on the language, the project and the team. Use the width that your style guide or formatter expects. The table below shows common choices.

Common tab widths by language and format
Tab width Commonly used for Notes
2 spaces JavaScript, TypeScript, HTML, CSS, YAML, JSON Short indentation that keeps deep nesting readable
4 spaces Python, Java, C#, PHP, Kotlin, Swift The most common width, and the PEP 8 standard for Python
8 spaces Classic terminals, some C and Makefile style code The default tab stop in many terminals
Custom Team rules, documents, plain text tables Use any number that matches your own standard

Align to Tab Stops: What It Does

A simple conversion replaces every tab with the same number of spaces. A real tab, however, moves the text to the next tab stop, so the number of columns it fills depends on where it is on the line. When you turn on Align to tab stops, the converter works the same way an editor does. It counts the current column and adds only the spaces needed to reach the next stop. This keeps columns of text and tables lined up after conversion, which is especially useful for data separated by tabs and for text that is aligned in the middle of a line.

Convert All Tabs or Only Indentation?

  • Every tab in the text: Use this for plain text, tables and data where tabs are also used between words or columns.
  • Leading indentation only: Use this for code, where only the tabs at the start of each line should change and tabs inside strings or after code should stay untouched.

Why Tabs and Spaces Cause Problems

  • Different display width: The same tab looks like 2, 4 or 8 spaces in different editors, so alignment can break.
  • Mixed indentation: A file that mixes tabs and spaces can look correct in one editor and wrong in another.
  • Strict formats: YAML does not allow tabs for indentation, and Python 3 rejects inconsistent mixing.
  • Pasting into web forms and chats: Tabs are often removed or turned into a single space, so the layout is lost.
  • Version control noise: Mixed whitespace makes changes harder to review in a diff.

Who Uses a Tab to Space Converter?

  • Developers: Fix indentation before committing code or pasting it in documentation.
  • Students: Clean code copied from slides, books or websites.
  • Technical writers: Make code samples look identical in every viewer.
  • Data and spreadsheet users: Turn tab separated text into a space aligned layout.
  • Anyone sharing text: Keep alignment when text is pasted into an email or chat.

Tips for Clean Indentation

  • Follow your project style: Check the style guide or formatter configuration and use the same width.
  • Convert only indentation in code: This protects tabs that are part of string values.
  • Trim trailing spaces: Removing spaces at the end of lines keeps diffs clean.
  • Check the result in your editor: Open the converted text and confirm that the layout looks as expected.
  • Keep a backup: Keep the original in case you need to compare or revert.

Troubleshooting: Why Does My Text Still Look Misaligned?

  • Proportional font: Alignment only looks correct in a monospaced font, so view the text in a code editor.
  • Mixed tab widths: If the original was written with 2 space tabs and you convert with 4, the layout changes. Choose the width it was written with.
  • Spaces were already there: Leading spaces are not tabs, so they are not changed when converting tabs to spaces.
  • Wrong conversion scope: Switch between every tab and leading indentation only to see which gives the right result.

Is It Safe to Paste My Code Here?

Yes. The conversion runs inside your browser, so your text and code are not uploaded, saved or stored. As a general habit with any online tool, avoid pasting secrets such as passwords, private keys or API tokens.

More Free Text Tools You May Need

This tool is often one step in a bigger text workflow. These related free tools help with the rest of the job:

Free Tab to Space Converter: Fast, Private and Accurate

Our tab to space converter was built to fix indentation quickly and safely. It supports 2, 4, 8 and custom tab widths, column aware tab stops and conversion in both directions, with no signup and no uploads.

Ready to try it? Scroll back up, paste your text and get consistent indentation in a second.

ADVERTISEMENT
Demo Ad 300 x 250 300 x 250
COMMON QUESTIONS

Tab to Space Converter FAQ

Quick answers about converting tabs to spaces, choosing a tab width, aligning to tab stops and converting spaces back to tabs.

How do I convert tabs to spaces online for free?

Paste your text or code into the input box, keep Tabs to Spaces selected, choose a tab width of 2, 4, 8 or a custom number, and the converted result appears instantly. Then copy it or download it as a TXT file. The tool is free, needs no signup and has no usage limit.

How many spaces should I use to replace a tab?

Use the width that your project already follows. Four spaces is the most common choice for Python, Java, C# and PHP, two spaces is popular for JavaScript, HTML, CSS, JSON and YAML, and eight spaces matches classic terminal and Linux kernel style. You can also enter any custom width from 1 to 16.

What does the Align to tab stops option do?

It makes the converter behave like a code editor. Instead of replacing every tab with the same number of spaces, it fills only the distance to the next tab stop, so tab-separated columns and mid-line tabs keep their original alignment. Leave it off for plain indentation conversion, and turn it on for tables and aligned text.

Can I convert spaces back to tabs?

Yes. Choose the Spaces to Tabs mode and set the same tab width the text was written with. The tool groups the spaces at the start of each line into tab characters and keeps any leftover spaces, so the visual indentation does not change.

Will converting tabs to spaces break my code?

For most languages, including Python, JavaScript, Java and YAML, converting tabs to spaces is safe and often fixes indentation errors. Be careful with Makefiles, which need real tabs on recipe lines, and with tab-separated data files where tabs are field separators. If tabs inside strings matter, use the Leading indentation only option.

Does the converter change my line breaks or other characters?

No. Letters, numbers, symbols, emoji and line breaks stay exactly as they are. Only the tab characters (or the spaces, in the reverse mode) are changed, plus trailing spaces if you switch on the trim option.

Is it safe to paste my code into this tab to space converter?

Yes. The conversion runs in your own browser, so your text is not uploaded, saved or stored on our servers, and no account is required. As a general habit, avoid pasting passwords, API keys or other secrets into any website.

ADVERTISEMENT
Demo Ad 728 x 90 320 x 100