Unindent Text

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

Input

Result

Client-Side Privacy
Instant Response
100% Free Forever

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?
No. Unlike Trim tools, Unindent preserves vertical spacing. Empty lines remain, maintaining readability.
What if I have mixed Tabs and Spaces?
Auto-Detect treats all whitespace as character length. For mixed indentation, results may vary. It is recommended to convert tabs to spaces first.
Can I unindent just one line?
This tool operates on entire blocks. For single lines, use a text editor.

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.

More Text Tools

Browse All

Split Text

Repeat Text

Join Text

Reverse Text

Truncate Text

Slice Text

Trim Text

Left Pad Text

Right Pad Text

Left Align Text

Right Align Text

Center Text

Indent Text

Justify Text

Word Wrap Text

Reverse Letters in Words

Reverse Sentences

Reverse Paragraphs

Swap Letters in Words

Swap Words in Text

Duplicate Words in Text

Remove Words from Text

Duplicate Sentences in Text

Remove Sentences from Text

Replace Words in Text

Add Random Words to Text

Add Random Letters to Words

Add Errors to Text

Remove Random Letters from Words

Remove Random Symbols from Text

Add Symbols Around Words

Remove Symbols from Around Words

Add Text Prefix

Add Text Suffix

Remove Text Prefix

Remove Text Suffix

Add Prefix to Words

Add Suffix to Words

Remove Prefix from Words

Remove Suffix from Words

Insert Symbols Between Letters

Add Symbols Around Letters

Remove Empty Text Lines

Remove Duplicate Text Lines

Filter Text Lines

Filter Words

Filter Sentences

Filter Paragraphs

Sort Text Lines

Sort Sentences in Text

Sort Paragraphs in Text

Sort Words in Text

Sort Letters in Words

Sort Symbols in Text

Randomize Letters in Text

Scramble Words

Randomize Words in Text

Randomize Text Lines

Randomize Text Sentences

Randomize Text Paragraphs

Calculate Letter Sum

Unwrap Text Lines

Extract Text Fragment

Replace Text

Find Text Length

Find Top Letters

Find Top Words

Calculate Text Entropy

Count Words in Text

Print Text Statistics

Find Unique Text Words

Find Duplicate Text Words

Find Unique Text Letters

Find Duplicate Text Letters

Remove Duplicate Text Words

Count Text Lines

Add Line Numbers

Remove Line Numbers

Convert Text to Image

Change Text Font

Remove Text Font

Write Text in Superscript

Write Text in Subscript

Generate Tiny Text

Write Text in Bold

Write Text in Italic

Write Text in Cursive

Add Underline to Text

Add Strikethrough to Text

Generate Zalgo Text

Undo Zalgo Text Effect

Create Text Palindrome

Check Text Palindrome

Change Text Case

Convert Text to Uppercase

Convert Text to Lowercase

Convert Text to Title Case

Convert Text to Proper Case

Randomize Text Case

Invert Text Case

Add Line Breaks to Text

Remove Line Breaks from Text

Replace Line Breaks in Text

Randomize Line Breaks in Text

Normalize Line Breaks in Text

Fix Paragraph Distance

Fancify Line Breaks in Text

Convert Spaces to Newlines

Convert Newlines to Spaces

Convert Spaces to Tabs

Convert Tabs to Spaces

Convert Comma to Newline

Convert Newline to Comma

Convert Column to Comma

Convert Comma to Column

Convert Commas to Spaces

Convert Spaces to Commas

Replace Commas in Text

Remove Extra Spaces from Text

Increase Text Spacing

Normalize Text Spacing

Randomize Text Spacing

Replace Text Spaces

Remove All Whitespace from Text

Remove Text Punctuation

Remove Text Diacritics

Remove Text Diacritics

Increment Text Letters

Decrement Text Letters

Add Quotes to Text

Remove Quotes from Text

Add Quotes to Words

Remove Quotes from Words

Add Quotes to Lines

Remove Quotes from Lines

Add Curse Words to Text

Censor Words in Text

Anonymize Text

Extract Text from HTML

Extract Text from XML

Extract Text from BBCode

Extract Text from JSON

JSON Stringify Text

JSON Parse Text

Escape Text

Unescape Text

ROT13 Text

ROT47 Text

Generate Text of Certain Length

Generate Text from Regex

Extract Regex Matches from Text

Highlight Regex Matches in Text

Test Regex with Text

Printf Text

Rotate Text

Flip Text Vertically

Rewrite Text

Change Text Alphabet

Replace Text Letters

Convert Letters to Digits

Convert Digits to Letters

Replace Words with Digits

Replace Digits with Words

Duplicate Text Letters

Remove Text Letters

Erase Letters from Words

Erase Words from Text

Visualize Text Structure

Highlight Letters in Text

Highlight Words in Text

Highlight Patterns in Text

Replace Text Vowels

Duplicate Text Vowels

Remove Text Vowels

Replace Text Consonants

Duplicate Text Consonants

Remove Text Consonants

Convert Text to Nice Columns

Convert Nice Columns to Text

Generate Text Unigrams

Generate Text Bigrams

Generate Text N-Grams

Generate Text Skip-Grams

Create Zigzag Text

Draw Box Around Text

Convert Text to Morse

Convert Morse to Text

Calculate Text Complexity

URL Encode Text

URL Decode Text

HTML Encode Text

HTML Decode Text

Convert Text to URL Slug

Convert Text to Base64

Convert Base64 to Text

Convert Text to Binary

Convert Binary to Text

Convert Text to Octal

Convert Octal to Text

Convert Text to Decimal

Convert Decimal to Text

Convert Text to Hexadecimal

Convert Hexadecimal to Text