How to Convert Tabs to Spaces Online
To convert tabs to spaces online, paste your text into a free browser-based converter, choose how many spaces each tab should become — usually 2, 4, or 8 — and copy the converted text back out. The whole job takes under a minute, needs no install, and works fine in a tool that runs in your browser, so your text never has to be sent to a server.
It sounds simple, and most of the time it is. The trouble starts when people assume a tab is just a fixed bunch of spaces. It is not: a tab jumps to the next tab stop, so the same tab can look like two spaces in one spot and eight in another. That is why code that looks lined up in one editor looks off in another, and why a spreadsheet paste can land in the wrong columns.
Key takeaways
- A tab is not a fixed number of spaces — it jumps to the next tab stop, so a straight one-for-one swap and a tab-stop conversion can give different results.
- For most code, match the project’s rule: 2 spaces for JavaScript and web work, 4 for Python and Java, and check before you guess.
- Convert leading tabs only when you are fixing indentation, and convert the whole text only when tabs are also being used as separators inside lines.
- Keep a copy of the original before you convert, because once tabs become spaces you cannot always tell where the tabs used to be.
- For plain text and documents, converting tabs to spaces makes the layout stay put wherever the text is pasted next.
What a tab actually does, and why it causes trouble
Think of a tab like a jump, not a gap. Press Tab in a document and the cursor hops forward to the next stop on an invisible ruler. If the stops are every eight characters, a tab near the start of a line jumps a long way, while a tab near the end of a short word jumps a short way. Spaces, on the other hand, are dumb and honest: one space is always one space, wherever it sits.
That difference stays invisible until you move text between programs. Your editor might use four-character tab stops, your colleague’s eight, and a web page might render a tab as eight spaces or squeeze it down. Suddenly neat columns fall apart and comments drift away from their code. Converting to spaces removes the guesswork, so every reader sees the same layout you saw.
One more wrinkle: some converters do a fixed swap, turning every tab into four spaces wherever it sits. Others do a tab-stop conversion, giving each tab just enough spaces to reach the next stop. For leading indentation the two usually agree, but inside a line — in a table or columns of data — they can disagree, and the tab-stop version is the one that keeps columns lined up.
Picking 2, 4, or 8 spaces
There is no single right answer here, only the answer your project already uses. Mixing two conventions in one file is worse than either one on its own, because then nobody can tell at a glance how deep a block is indented. Before you convert, take ten seconds to check what the file already does. Open it, look at a few indented lines, and count. If most lines use two spaces per level, use two. If they use four, use four.
As a rough guide, web code — JavaScript, TypeScript, HTML, CSS — usually goes with two spaces. It keeps deeply nested markup from marching off the right edge of the screen. Python, Java, and a lot of older C-style code usually go with four. Eight shows up in older Unix code and in some system tools, and it is also the default tab width in many plain-text displays, which is why a tab often looks like eight spaces when you paste code into an email or a chat window.
If nobody has set a rule, four is a safe middle ground, and it is worth writing your choice down — in the project readme or your editor’s settings — so the next paste does not undo your work.
How to convert tabs to spaces online, step by step
First, find a converter that runs in your browser. You want one with a visible setting for spaces per tab, and ideally a choice between leading indentation only and the whole text. Paste your text into the input box. If the text came from a document, paste it as plain text where you can, so hidden formatting does not smuggle extra characters in.
Next, set the number of spaces per tab. Start with the number your project uses, and if you are not sure, try four and look at the result. Then choose the scope. Leading indentation only is the safe default for code: it changes the spaces at the start of each line and leaves tabs inside the line alone. Whole-text conversion is the right call when tabs are acting as separators, like in a table pasted from a spreadsheet, because those interior tabs need to become spaces too.
Run the conversion, then read the result before you copy it. Check that nested blocks still step in evenly and any columns still line up, especially on lines that mixed tabs and spaces to begin with. When it looks right, copy it back — and save a copy of the original first if you are replacing a file.
The same job in Word, Google Docs, and your code editor
You do not always need a browser tool. In Word, press Ctrl+H to open Find and Replace, type ^t in the Find box (that is Word’s code for a tab), type the spaces you want in the Replace box, and click Replace All. In Google Docs there is no tab code in Find and Replace, so the practical route is to copy the text into a browser converter, convert it there, and paste it back — or paste into a plain-text editor first and use its conversion command.
Code editors make this easiest of all. In VS Code, open the Command Palette and run “Convert Indentation to Spaces”, or set the editor to insert spaces when you press Tab so new code never adds tabs. Notepad++ has an Edit menu option for the whole file. Doing it in your editor converts the file in place, and you can undo with one keystroke if the result looks wrong.
For a spreadsheet, the story is different: tabs there are usually column separators, not indentation, so converting them to spaces loses the column structure. Paste into the spreadsheet first and let it split the columns, or convert tabs to commas if you need a CSV file.
When to convert only the leading tabs
Leading tabs are the tabs at the very start of a line, before any other character. They are almost always indentation, and they are the tabs that cause the classic “looks fine on my machine” problem. Converting just those is the gentlest fix: the structure of the code is normalised, and everything inside the lines — strings, comments, data columns — is left exactly as it was.
Take a Python file as an example. Python cares deeply about indentation: blocks are defined by how far lines are indented, and mixing tabs and spaces in one file is an error, not a style preference. The Python documentation itself warns that tabs and spaces must not be mixed for indentation, because a tab’s width depends on where it sits. Converting the leading tabs to a consistent number of spaces, and then keeping spaces from then on, is the standard fix, and it is the one most Python guides recommend.
Whole-text conversion, by contrast, touches every tab in the file, including ones inside strings and data. That is what you want for a tab-separated table you are turning into plain spaced text, but it can change the meaning of a string that deliberately contains a tab, or flatten a column layout that a tab was holding apart. Rule of thumb: if you are fixing how code looks, convert leading tabs only. If you are reformatting data, convert the whole text, and check the columns afterwards.
Common mistakes that are easy to avoid
The most common mistake is converting twice. Someone converts tabs to spaces, pastes the result into a document that reintroduces tabs, and converts again, each time drifting a little further from the original layout. Convert once, from a saved original, and keep that original until you have checked the result.
The second mistake is picking a tab size that does not match the file. A file indented with eight-space tabs, converted at two spaces per tab, will look squashed: nested blocks will be hard to tell apart. A file indented with two-space tabs, converted at eight, will look stretched and wasteful. Both are fixable by converting again from the original, which is another reason to keep it.
The third mistake is forgetting that spaces and tabs can hide together in a line — two spaces then a tab, or a tab then spaces. The result can look uneven even though every tab was converted correctly, because the original line was uneven to begin with. Turn on visible whitespace in your editor, so tabs show as arrows and spaces as dots, and those lines are easy to spot.
Finally, do not convert tabs inside a file you do not understand. Config files like YAML also care about indentation, so convert a copy, test it, and only then replace the original.
| Job | Best approach | Watch out for |
|---|---|---|
| Fix code indentation | Leading tabs only, matching the project’s space count | Mixed tabs and spaces on the same line |
| Clean a pasted table | Whole-text tab-stop conversion, then check columns | Tabs inside quoted strings or data |
| Tidy a document or essay | Browser converter, 4 spaces, leading only | Tabs used to centre or align text by hand |
| Prepare a spreadsheet paste | Do not convert — paste first and let columns split | Converting turns column separators into plain gaps |
| Normalise a whole project | Your editor’s convert command, one file at a time | Config files like YAML that depend on exact indentation |
Can I convert tabs to spaces online for free without signing up?
Yes. Tab conversion is a tiny job, and plenty of free browser tools do it with no account, no install, and no upload. Pick one that runs in your browser — the conversion happens on your own computer — and you can paste, convert, and copy in under a minute. If a tool asks you to create an account for something this small, find a different one.
How many spaces should each tab become?
Match whatever the file or project already uses: 2 spaces for most web code, 4 for Python and Java, 8 for older Unix-style code. If nothing has set a rule, 4 is a sensible default. The worst choice is a number that disagrees with the rest of the file, because then the indentation stops meaning anything consistent.
Will converting tabs to spaces break my Python code?
Done properly, it fixes Python code rather than breaking it, because Python rejects files that mix tabs and spaces for indentation. Convert the leading tabs to one consistent number of spaces, keep spaces from then on, and run the file to check. Convert a copy first if the file matters, and do not convert tabs that sit inside strings where the tab character itself is part of the data.
What is the difference between fixed replacement and tab-stop conversion?
Fixed replacement turns every tab into the same number of spaces, wherever it sits. Tab-stop conversion turns each tab into just enough spaces to reach the next tab stop, so a tab after three characters becomes one space and a tab at a line start becomes four. For leading indentation they usually agree; for tables and columns, the tab-stop version keeps things lined up.
Should I convert tabs in a spreadsheet or CSV file?
Usually no. In a spreadsheet paste, tabs are column separators, and turning them into spaces merges the columns into one run of text. Paste into the spreadsheet first so the columns split properly, or convert tabs to commas if you need a CSV file. Convert tabs to spaces only when you actually want spaced-out plain text, not a table.
FAQ
How do I convert tabs to spaces in Word?
Press Ctrl+H, type ^t in Find, type your chosen spaces in Replace, and click Replace All. That swaps every tab in the document for spaces. Check tables afterwards, because tabs inside a table can be holding columns apart.
How do I convert tabs to spaces in VS Code?
Open the Command Palette with Ctrl+Shift+P, run “Convert Indentation to Spaces”, and VS Code rewrites the file’s indentation in place. You can also set the editor to insert spaces on Tab so new code never adds tabs again.
Is it safe to paste private text into an online tab converter?
It is safe with a tool that processes text locally in your browser, because the text never leaves your device. Avoid tools that upload your text to a server for a job this simple, and do not paste passwords, keys, or personal data into any online tool you have not checked.
How do I convert tabs to spaces on my phone?
Open a browser-based converter on your phone, paste the text, pick the spaces per tab, and copy the result back into your notes app, email, or document. No app install is needed, though checking the result is harder on a small screen, so keep the original until you have looked it over on a bigger screen.
Closing
Tabs are useful when you are typing, and a nuisance when you are sharing. The fix is small — paste, pick a number, check the result, copy it back — but the habit behind it matters more: use one convention, match the project you are working in, and keep the original until you are sure. Do that, and the next person who opens your file will see exactly what you saw, on any editor, on any machine. For a related tidy-up, see how to remove tabs from text online when you want them gone entirely, how to remove spaces from text online when the gaps themselves are the problem, and how to remove trailing spaces from text online for the invisible spaces at the ends of lines. Python’s own documentation on indentation and tab handling explains why mixing the two causes errors in the first place.
