Tabs to Spaces Converter (and back)
Convert leading indentation between tabs and spaces with a configurable tab width, in your browser.
How to use
- Paste your code or text into the input box.
- Choose a direction (tabs to spaces or spaces to tabs) and set the tab width.
- Copy the re-indented result from the output box.
About this tool
ShowHide
Convert indentation between tabs and spaces at a tab width you choose, from one to eight. Only the leading whitespace on each line is touched, which is what keeps the conversion safe: a tab inside a string literal, a Markdown table or an aligned comment survives untouched, where a blind find-and-replace would wreck all three. Tab stops are handled properly too — a tab advances to the next multiple of the tab width rather than expanding to a fixed number of spaces, so a file that mixes tabs and spaces in the same indent comes out with its levels intact instead of drifting. Useful for meeting a project's style rules, fixing a snippet pasted from somewhere else, or preparing code for a system with an opinion about whitespace.
Frequently asked questions
Does it change spaces inside a line?
No. Only the leading whitespace at the start of each line is converted, so alignment and spaces within your text stay exactly as they were.
What does tab width do?
It sets how many columns a tab advances to. Converting tabs to spaces uses it to expand each tab to the next tab stop; converting spaces to tabs uses it to pack runs of spaces back into tabs.
How is mixed tab/space indentation handled?
Each line's leading whitespace is measured in visual columns using tab stops, then re-emitted entirely as tabs or spaces, so inconsistent indentation gets normalized.
Is my text sent anywhere?
No. Conversion happens entirely in your browser; nothing is uploaded.
Tabs or spaces — does it actually matter?
For accessibility, tabs have a real argument: a tab is one character whose width the reader chooses, so someone using a large font or a braille display can set it to suit them, while spaces hard-code the author's choice. Beyond that it is a project convention, and the one that matters is that everyone in the repository follows the same one.
Why did my alignment survive but my indentation change?
Because only the leading whitespace is converted. Spaces used mid-line to line up a comment or a table stay exactly as they were, which is deliberate — converting those would shift columns that were aligned by eye. It is also why mixing tabs for indentation with spaces for alignment survives this tool intact.
Related tools
Word Wrap — Reflow Text to a Column Width
Hard-wrap text to a fixed line width, breaking at word boundaries, in your browser.
Text
Smart ↔ Straight Quote Converter
Convert between straight (") and typographic / curly (“ ”) quotes — and back — with locale-aware styles.
Text
Morse Code Translator
Convert text to and from international Morse code. Supports A-Z, 0-9, punctuation. Customizable letter and word separators.
Text
Soundex Phonetic Code Generator
Generate the American Soundex code for names or words — a 4-character phonetic key that groups similar-sounding spellings together.
Text
Case Converter
Convert text between UPPER, lower, Title, camelCase, snake_case and more.
Text
Markdown Table to CSV Converter
Convert a GitHub-flavored Markdown table into CSV, TSV or semicolon-separated rows, in your browser.
Text