— Spaces to Tabs Converter

Convert Spaces to Tabs

Quick Tips

  • This tool runs entirely in your browser - your data stays private.
  • Press Ctrl+V (Cmd+V on Mac) to quickly paste text.
  • Use the Copy button to save your result to clipboard.
  • Bookmark this page for quick access!

Convert space indentation to tab characters.

Examples

Input
    line1
        line2
Output
	line1
		line2 (4-space tabs)
Input
  two spaces
Output
	two spaces (2-space tabs)
Input
        deep indent
Output
		deep indent (4-space tabs)

Frequently Asked Questions

By default, only leading spaces (indentation at the start of lines) are converted. Spaces within lines, in strings, or for alignment are preserved. This targets indentation style without affecting code content.

Lines with partial indentation (e.g., 6 spaces with 4-space tabs) can be handled different ways: convert what aligns with tab stops, round to nearest, or preserve partial spacing. Choose based on whether the irregularity is intentional.

The make utility was designed in 1976 to require tabs for recipe lines. This wasn't considered problematic then, but now causes frequent issues. Make will fail with "missing separator" errors if spaces are used instead of tabs.

For most languages, indentation with tabs works identically to spaces. Python is sensitive to consistent indentation—don't mix tabs and spaces within a file. The conversion should be all-or-nothing for Python code.

Count the spaces used for one level of indentation in your file. Common values are 2 or 4 spaces per indent level. Set the conversion width to match so each indent level becomes exactly one tab.

Cookie Preferences

We use cookies to enhance your experience. By continuing to visit this site you agree to our use of cookies.

Cookie Preferences

Manage your cookie settings

Essential Cookies
Always Active

These cookies are necessary for the website to function and cannot be switched off. They are usually set in response to actions made by you such as setting your privacy preferences or logging in.

Functional Cookies

These cookies enable enhanced functionality and personalization, such as remembering your preferences, theme settings, and form data.

Analytics Cookies

These cookies allow us to count visits and traffic sources so we can measure and improve site performance. All data is aggregated and anonymous.

Google Analytics _ga, _gid

Learn more about our Cookie Policy