How to use the indentation converter
- Paste your code into the Code box. The sample is a small function indented with tabs.
- Choose Convert to: Spaces or Tabs.
- Set Tab width (spaces per level in the input), 1–12, default 4.
- For spaces, set Spaces per level in the output (default 2).
- Leave Only change leading indentation ticked, then copy the Converted text.
What it does and when to use it
Teams and languages disagree about indentation. Go and Makefiles use tabs, Python’s PEP 8 asks for 4 spaces, much JavaScript and YAML uses 2. Code copied between projects, or from a Stack Overflow answer, rarely matches the house style, and a mixed file makes diffs noisy. This converter changes only the indentation, so you can match a project’s editor settings before committing.
It does not look at brackets or keywords, so it works on any text, from HTML and SQL to Markdown lists. If the indentation itself is wrong rather than just the wrong size, use a structure-aware tool such as the code beautifier. To fix line endings and trailing spaces at the same time, follow up with the whitespace normalizer, and use the code diff viewer to confirm nothing else changed.
How it works
For each line, in your browser, the tool:
- Measures the leading whitespace in columns. A space adds 1; a tab jumps to the next multiple of the tab width.
- Splits that width into whole levels and a remainder.
- Writes the new indent: one tab per level for Tabs, or levels × your output size for Spaces, followed by the remainder as spaces.
- Copies the rest of the line unchanged, unless Only change leading indentation is unticked. Then each tab inside the line becomes tab-width spaces (for Spaces) or stays a tab.
Worked examples
These are the tool’s own outputs.
Tabs to 2 spaces (the sample).
function f() {
if (x) {
return 1;
}
}
Each tab was one level; each level is now 2 spaces.
HTML from 4 spaces to tabs. <ul> with two <li> lines indented by 4 spaces, converted to Tabs, gives one tab before each <li>.
Python from 4 spaces to 2. def f():, if x: and return 1 at 0, 4 and 8 spaces come out at 0, 2 and 4.
A partial level. With Tabs and a width of 4, two (2 spaces) stays as 2 spaces, and a 6-space line becomes a tab plus 2 spaces, so alignment is not lost.
Limits and tips
- Inner tabs are not aligned to tab stops. With the leading-only box unticked,
a, tab,bbecomesaand 4 spaces thenb, notapadded to column 4. - Set the input width correctly. If a 2-space file is read with width 4 and output size 2, lines at 2 and 4 spaces both end up at 2, so two levels merge.
- Makefiles need tabs before commands; never convert them to spaces.
Frequently asked questions
What does Tab width mean here?
How do I change 4-space indentation to 2 spaces?
Should I untick Only change leading indentation?
Is this safe for Python or YAML?
How do we know nothing is uploaded? Test it yourself on the privacy proof page.