By Debmedia Technologies LLP · Kolkata, India · Updated
What Is a Spaces to Tabs Converter?
A spaces to tabs converter swaps the whitespace characters in a text for different ones. Spaces, tabs and new lines all look like empty gaps, but they behave differently. Code editors treat tabs and spaces differently when they indent, spreadsheets split cells on tabs, and lists are easiest to work with when each item sits on its own line.
This spaces to tabs converter handles four jobs: spaces to tabs, tabs to spaces, spaces to new lines and new lines to spaces. For tabs and spaces you can set the tab width to 2, 4 or 8.
How to Use This Converter
- Paste your text into the box.
- Choose what to convert from the list.
- If you work with tabs, pick how many spaces make one tab.
- Press Convert and copy the result.
What Each Conversion Does
| Conversion | Result | Typical use |
|---|---|---|
| Spaces to tabs | Every run of N spaces becomes one tab. | Changing the indent style of code. |
| Tabs to spaces | Each tab becomes N spaces. | Making layout look the same everywhere. |
| Spaces to new lines | Every word goes on its own line. | Turning a sentence into a list. |
| New lines to spaces | Lines are joined into one line. | Making a paragraph from a list. |
The tool replaces characters using the string functions described in the MDN reference for string replace, and it changes nothing except the whitespace you chose.
Tabs or Spaces?
- Tabs are one character per indent level. Each person can set the width they like, and files are slightly smaller.
- Spaces look the same in every editor, email and web page. Many style guides prefer them for that reason.
- Mixing both in one file causes crooked layouts, which is the main reason to convert.
Pick the style your project uses and convert everything to match.
Handy Uses Beyond Code
Paste a column of values from a spreadsheet and convert tabs to spaces to use them in a sentence. Turn a long line of keywords separated by spaces into one keyword per line with spaces to new lines, then sort or compare them. Join a pasted list into one line with new lines to spaces to fill a single-line field.
Related Tools
To remove extra gaps instead of converting them, use the whitespace remover. To split text at any character, try the text splitter, and to find and change specific characters, use find and replace. All processing runs in your browser.
Why This Converter Saves Time
Swapping whitespace by hand in a long text is slow and risky, because the characters look alike on the screen. This spaces to tabs converter does it exactly, in one step, and leaves everything else untouched. It is also a quick way to reshape lists, since turning spaces into new lines or the reverse changes the whole layout of a text in a second.
Frequently Asked Questions
Disclaimer: results are calculated in your browser from the numbers you enter. Check important results before you rely on them for money, health, safety or legal decisions.