How to use
Set the tab width
Type a number from 1 to 8 in Tab width, or click 2, 4 or 8. Match your project's style: 4 is standard for Python, and 2 is common in JavaScript and YAML.
Pick a direction and options
Click Tabs to spaces or Spaces to tabs and set the options for that direction. Tick Remove trailing spaces and tabs or Show whitespace in the result if you need them.
Paste and copy
Paste your text into Input, open a file, or press Try sample to load a Python function and a small table. Copy or download the converted text.
Why Tabs to Spaces Converter
- Tab stops keep columns aligned, like the Unix expand command.
- Spaces to tabs for indentation only, or aligned spaces too, like unexpand -a.
- Visible whitespace view and trailing whitespace removal.
- Width from 1 to 8, with one-click 2, 4 and 8.
Tabs or spaces: common language defaults
Most languages leave the choice to the team, but a few have firm rules or strong conventions. When in doubt, follow the formatter the project already uses. Many projects also include an .editorconfig file that sets indent_style and indent_size, and many editors follow it, some through a plugin.
| Language or file | Indentation | Notes |
|---|---|---|
| Python | 4 spaces | Recommended by PEP 8. Mixing tabs and spaces ambiguously is an error in Python 3. |
| Go | Tabs | gofmt, the standard formatter, indents with tabs. |
| JavaScript and TypeScript | 2 spaces is common | Prettier's default is 2 spaces; some teams use 4. |
| YAML | Spaces only | Tabs are not allowed for indentation. |
| Makefile | Tab before each recipe line | Spaces cause a missing separator error. |
| HTML and CSS | 2 spaces is common | No rule; follow the project's formatter. |