Skip to content
πŸ› οΈToolsShed

Text Indent Formatter

Add, remove, or adjust text indentation for any block of text.

About this tool

The Text Indent Formatter is a simple yet powerful tool for controlling whitespace at the beginning of text lines. Whether you're formatting code, organizing document structure, or preparing text for specific formatting requirements, this tool lets you add, remove, or adjust indentation quickly without manual editing. Proper indentation improves readability and helps maintain consistent formatting across documents.

Using the tool is straightforward: paste your text into the input field, select your desired indentation action (add spaces, tabs, or remove existing indentation), and specify the amount or type of indentation. The formatter processes your text instantly and displays the result, ready to copy. Common use cases include converting between spaces and tabs, standardizing indentation levels across code snippets, preparing text for publication, or fixing inconsistent spacing in imported content.

Frequently Asked Questions

Code Implementation

# Add, remove, or set indentation for each line
def add_indent(text, indent="    ", levels=1):
    prefix = indent * levels
    return "\n".join(prefix + line for line in text.splitlines())

def remove_indent(text, indent="    ", levels=1):
    result = []
    for line in text.splitlines():
        for _ in range(levels):
            if line.startswith(indent):
                line = line[len(indent):]
        result.append(line)
    return "\n".join(result)

def set_indent(text, indent="    ", levels=1):
    prefix = indent * levels
    return "\n".join(prefix + line.lstrip() for line in text.splitlines())

code = "def foo():\n    x = 1\n    return x"
print(add_indent(code, "  ", 1))
print(remove_indent(code, "    ", 1))
print(set_indent(code, "\t", 1))

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.