LazyTools – Header

Spaces to Tabs Converter

Convert spaces to tabs (or tabs to spaces) with configurable tab width, leading-only mode, mixed indent detection, live preview in monospace, and download. Bidirectional, free, client-side, no sign-up.

Client-Side ✓ Free Forever No Sign-Up
4.4K+monthly searches
2-in-1bidirectional

Spaces ↔ Tabs Converter

Runs in your browser — nothing sent to a server
Conversion direction
Tab width (spaces per tab)
Tab =
spaces
→···(4 sp)
⚠️ Mixed indentation detected — this text contains both tabs and spaces for indentation. Results may be inconsistent.
Conversion options
Clean-up options
0 Conversions
0 Lines
0 Lines changed
Size change
Input 0 chars
Output 0 chars
4.7/5
563 ratings

Rate this tool

How useful was the Spaces to Tabs converter?

Convert indentation in 4 steps

Choose direction, set tab width, paste your code, and copy or download.

1

Choose direction

Select Spaces → Tabs to convert space-indented text to tabs, or Tabs → Spaces to go the other way. Use Swap I/O to reverse the result.

2

Set tab width

Choose 2, 4, or 8 spaces per tab — or enter a custom number. The preview shows exactly how one tab will be represented in the output.

3

Paste your code

With Live preview on, the output updates instantly. If mixed indentation is detected, a warning appears. Enable "Leading spaces only" to protect inline spacing.

4

Copy or download

Click Copy to clipboard to paste into your editor, or Download .txt to save the file. Stats show conversions made and lines changed.

Advertisement
728 × 90 — Leaderboard Ad

Frequently asked questions

Everything you need to know about converting between spaces and tabs.

Tab width defines how many spaces equal one tab character. 2 spaces is common in JavaScript, TypeScript, and web projects. 4 spaces is the Python standard (PEP 8) and common in C, Java, and general use. 8 spaces is the traditional Unix/C standard. Match the tab width to your project's coding style to ensure indentation levels align correctly after conversion.
With Leading spaces only enabled, the tool only converts spaces that appear at the start of each line (used for indentation). Spaces within the line — in string literals, comments, or inline alignment like x = 1 — are left untouched. This is the recommended mode for code because converting inline spaces would break string content, alignment patterns, and SQL formatting.
Mixed indentation means some lines are indented with spaces and others with tabs. This is a common problem when multiple developers use different editor settings or when code is pasted from different sources. It causes visual misalignment, confuses linters, and in Python it can cause TabError: inconsistent use of tabs and spaces in indentation. The tool detects and warns you when mixed indentation is present.
Only if used incorrectly. Python and YAML are indentation-sensitive — changing indentation characters changes the file's structure. Converting spaces to tabs in Python is safe only if every indentation level uses exactly the right number of spaces. Enable "Leading spaces only" and make sure your tab width matches the indentation in your file (usually 4 for Python). Always test the converted file after conversion.
In normal mode, exactly N spaces are replaced by one tab (where N is your tab width). So 4 spaces → 1 tab, 8 spaces → 2 tabs. With Collapse enabled, any sequence of one or more spaces (at the start of a line in leading-only mode) is replaced by a single tab, regardless of count. This is useful for normalising inconsistent indentation where some lines have 3 spaces and others have 5.
Yes — click Tabs → Spaces to reverse the conversion. Each tab character is expanded to your chosen number of spaces. This is useful when you receive code that uses tabs but your project requires spaces, or when preparing code to paste into a system that doesn't render tabs (like most web browsers and email clients).
No. Everything runs in your browser using JavaScript. Your code never leaves your device and is never sent to LazyTools or any third party. This makes it safe to use with proprietary code, client projects, and confidential source files.

LazyTools vs other space/tab converters

How we compare on the features developers actually need.

Feature LazyTools ✦ texttools.org onlinetexttools.com freetexttools.org toolamo.com
Spaces → Tabs conversion
Tabs → Spaces (bidirectional)
Configurable tab width (2/4/8/custom)
Leading spaces only (code-safe)
Collapse N spaces → 1 tab
Mixed indentation detection
Tab width preview
Monospace font display
Swap input/output
Live preview (auto-converts)
Live stats (conversions, lines affected)
Side-by-side input / output
Trim trailing whitespace
Download output
100% client-side (private)