Unindent Text
Remove indentation from text lines. Delete all leading whitespace or reduce indentation by specific levels. Perfect for code cleanup.
Input
Result

Get Free Money Making Tips
Join 2,000+ smart readers getting side-hustle ideas, passive income strategies, and proven finance tips delivered straight to your inbox.
What is Unindentation (Dedent)?
Unindentation—technically called “Dedenting”—removes leading whitespace from lines while preserving internal hierarchical structure. It is essential for code formatting, text normalization, and document cleanup.
Dedent vs. Left Align: The Critical Difference
Many users confuse Unindent with Left Align, but they serve different purposes:
- Left Align: Destructively removes all leading whitespace from every line. Every line starts at column 0, destroying nested code structures.
- Unindent (Dedent): Calculates the minimum common whitespace across all lines and removes only that amount. Nested indentation is preserved relative to the block.
How to Use the Professional Unindent Tool
-
Auto-Detect (Recommended):
- Scans the entire block of text.
- Identifies the line with the least indentation (e.g., 4 spaces).
- Removes exactly that amount from every line.
- Result: The block moves left, but nested structures remain intact.
-
Fixed Removal:
- Remove a specific number of spaces or tabs (e.g., 2 spaces or 1 tab).
- If a line has fewer spaces than specified, it will be stripped entirely.
- Useful for manual or consistent shifts, but less intelligent than Auto-Detect.
Technical Methodology: Common Prefix Algorithm
The Dedent engine uses a scan-and-strip approach to safely remove leading whitespace:
| Step | Logic | Description |
|---|---|---|
| Scan | lines.filter().map(l => l.search(/S/)) |
Finds the index of the first non-whitespace character in every non-empty line. |
| Min-Max | Math.min(...indices) |
Determines the global minimum indentation level (the “Base”). |
| Slice | line.slice(Base) |
Removes the base substring from the start of each line, preserving nested structure. |
Real-World Industry Applications
- StackOverflow Cleanup: Remove excess indentation when copying code from forums.
- Template Literals: Fix multi-line JavaScript strings with unwanted indentation.
- YAML/Python Editing: Shift configuration blocks from child to root nodes without breaking nesting.
Frequently Asked Questions
Will this remove empty lines?
What if I have mixed Tabs and Spaces?
Can I unindent just one line?
Standardization and Code Hygiene
Clean code standards (Robert C. Martin, Clean Code) recommend left-aligned code to reduce complexity. Using the Professional Unindent Utility refactors your snippets, decreases nesting depth, and improves readability for teams.