Indentation Styles — Tabs vs Spaces and Indent Sizes
Learn about indentation styles (tabs vs spaces, 2 vs 4 spaces), how they affect file size, and how minifiers and beautifiers handle indentation conversion. Includes team configuration tips.
Detailed Explanation
Indentation Styles in Code
Indentation style — tabs versus spaces and the number of spaces per level — is one of the most debated topics in software development. From a minification perspective, indentation is pure overhead that gets stripped entirely from production code.
Tabs vs. Spaces
Tabs (\t):
- One character per indent level regardless of visual width
- Visual width is configurable per editor (2, 4, 8 columns)
- Slightly smaller file size than spaces (1 byte vs 2-4 bytes per indent)
- Accessible — users can set their preferred visual width
Spaces:
- Consistent visual appearance across all editors and viewers
- More common in web development (JavaScript, CSS, HTML communities prefer spaces)
- 2-space indentation is the most popular in the JavaScript ecosystem
- 4-space indentation is common in Python, Java, and C#
File Size Impact
Indentation can be a surprisingly large portion of source files:
File: app.js (500 lines, avg 3 indent levels)
2-space indent: ~3,000 bytes of indentation
4-space indent: ~6,000 bytes of indentation
Tab indent: ~1,500 bytes of indentation
For a project with hundreds of files, this difference adds up — but it is completely eliminated by minification and well-handled by gzip compression.
How Minifiers Handle Indentation
Minifiers strip all indentation without caring whether the source uses tabs or spaces:
// 4-space indented source
function calculate(items) {
let total = 0;
for (const item of items) {
total += item.price;
}
return total;
}
// Minified output (same regardless of input indentation)
function calculate(t){let e=0;for(const l of t)e+=l.price;return e}
How Beautifiers Handle Indentation
Beautifiers let you choose the output indentation style. This means you can:
- Write code with your team's preferred style (2 spaces, 4 spaces, or tabs)
- Minify for production (indentation removed)
- Beautify for debugging (any indentation style you prefer)
Team Configuration
Use .editorconfig to enforce consistent indentation across a team:
[*]
indent_style = space
indent_size = 2
[*.py]
indent_size = 4
[Makefile]
indent_style = tab
Combined with Prettier or ESLint auto-formatting, this eliminates indentation debates entirely.
Use Case
Understanding indentation styles matters when configuring beautifiers, setting up team coding standards, and explaining to stakeholders why minification eliminates the file size debate entirely. It is especially relevant when migrating codebases between different style conventions.