Indent/Dedent Text Add or remove indentation from text with spaces or tabs.
Indent/Dedent Text
Add or remove indentation from text with spaces or tabs.
Paste Your Text
Paste text to indent or dedent.
Set Indentation Options
Choose indent/dedent mode, tab/space, and amount.
Copy the Adjusted Text
Copy the re-indented text.
What Is Indent/Dedent Text?
Indent/Dedent Text is a text processing tool that modifies the indentation of every line in a given text by either adding or removing whitespace characters. Developers and writers use it to format code, text blocks, and content for different contexts, solving the specific problem of inconsistent indentation that can make text difficult to read. For instance, when working with code, it's essential to remove leading whitespace to maintain clean and readable code structure.
This tool stands out due to its customizable features, such as the ability to choose between space-based and tab-based indentation. In space-based mode, users can specify the number of spaces to add or remove, ranging from 1 to 16, allowing for precise control over text indentation. The option to use tabs instead of spaces provides an alternative way to indent code with tabs, which is useful when working with certain programming languages or text editors.
When using it to add indentation to text, the tool prepends the specified whitespace characters to each line, making it a convenient text indentation tool for formatting text blocks and preparing content for different indentation contexts. Conversely, in dedent mode, it removes leading whitespace from each line up to the specified amount, effectively removing indentation from code and text. This functionality is particularly useful when trying to remove leading whitespace or dedent text online, making it easier to work with indent code that uses spaces or tabs.
Why Use Indent/Dedent Text?
-
Add consistent indentation to text blocks
-
Remove unwanted leading indentation
-
Switch between tab and space indentation
-
Configurable indent amount
Common Use Cases
Code Formatting
Add or remove indentation levels from code blocks.
Email Quoting
Indent text blocks for email quoting or documentation.
Content Preparation
Adjust indentation for pasting into different contexts.
Documentation
Format code examples with proper indentation.
Technical Guide
The tool works under the hood by using React's useState and useCallback hooks to manage its state and handle user input. When a user selects either indent or dedent mode, the tool updates its internal state with the chosen action. The amount of indentation and whether to use tabs or spaces are also stored in this state. The onProcess function is then called with the user's text input, at which point it splits the input into individual lines using the split method with a newline character as the separator.
In indent mode, the tool uses JavaScript's repeat method to create a string of spaces that will be prepended to each line, or a tab character if the useTab option is enabled. This string is then concatenated with each line using the map method and finally joined back together into a single string with newline characters in between. The TextToolLayout component from the @/components/shared directory handles rendering this output.
When operating in dedent mode, the tool checks each line to see if it starts with a tab character or spaces. If useTab is enabled, it simply removes one leading tab character if present using slicing. For space-based dedentation, it iterates over the characters at the start of each line and counts how many spaces are there until it reaches either a non-space character or has removed the specified amount of spaces. This count is then used to slice off the leading whitespace from the line.
The tool uses JavaScript's built-in string methods like split, map, join, and slicing for text manipulation, while React handles the user interface updates based on state changes triggered by user interactions with form elements such as radio buttons and checkboxes. The amount of spaces to add or remove is constrained between 1 and 16 using Math.max and Math.min functions when handling input from a number type input field.
Tips & Best Practices
-
1Indent adds whitespace to the beginning of every line
-
2Dedent removes whitespace from the beginning of every line
-
3Use tab mode when pasting into editors or projects that require tab characters
-
4Dedent will not remove more spaces than exist on each line
Related Tools
Tab to Spaces Converter
Convert tab characters to spaces with configurable tab width.
📝 Text Tools
Add Line Numbers
Add sequential line numbers to each line of text.
📝 Text Tools
Spaces to Tab Converter
Convert leading spaces to tab characters with configurable tab width.
📝 Text Tools
Prefix/Suffix Lines
Add a prefix and/or suffix to each line of text.
📝 Text ToolsFrequently Asked Questions
Q What is the difference between indent and dedent?
Q Does dedent remove all indentation?
Q Can I use tabs instead of spaces?
Q Does it affect empty lines?
Q How many spaces can I indent by?
About This Tool
Indent/Dedent Text is a free online tool by FreeToolkit.ai. All processing happens directly in your browser — your data never leaves your device. No registration or installation required.