A tab is not a fixed number of spaces. In plain text editors it's conventionally treated as 4 or 8 spaces; in Microsoft Word a default tab stop is 0.5 inches; in HTML the tab character collapses to a single space; and in code style guides it's usually 4 spaces or one hardware tab. The only number that survives every context is the one your specific tool defines.

That ambiguity is the whole answer, and it explains why the question keeps getting asked. Somebody pastes code into Word and the indentation explodes. Somebody sets "Tab = 4 spaces" in Notepad++ and the file looks different in a colleague's editor. Somebody writes an essay and gets told to indent with a tab, not five taps of the spacebar. Each of those is a different tab, behaving by a different rule.

What follows separates those contexts, gives you the number each one uses, and shows the conversion methods that actually hold up when you move text between programs.

The Short Answer Depends Entirely on Which Tab You Mean

The word "tab" covers at least four distinct things: a keyboard character (U+0009 in Unicode), a typographic indent in a word processor, a code indentation convention, and a paragraph-formatting control in HTML and CSS. They do not share a width.

The keyboard character has no width of its own. It's a control code telling the receiving software "advance to the next tab stop," and the software decides where that stop sits. That's why the same file can show 4 spaces in one program and 8 in another with no corruption β€” the byte didn't change, the rendering did.

Word processors replace that ambiguity with a physical measurement. Microsoft Word's default tab stop is 0.5 inches, adjustable in the Paragraph dialog under Tabs. Typographic convention in academic and legal writing, meanwhile, often wants a first-line indent of 0.5 inches rather than a tab character at all.

Code is a third world. The widely used Google style guides, including the Google C++ Style Guide and the Google Java Style Guide, specify 4 spaces and no tabs for indentation. Python's PEP 8 style guide for the standard library is stricter still: 4 spaces per level, and tabs are rejected outright because mixing them raises a TabError in Python 3.

Why 4 and 8 Are Both Correct Answers in Plain Text

In plain-text editors the tab width is a display setting, and the historical default is 8 columns. That number descends from typewriter tab stops and early terminal conventions, where a tab advanced to the next multiple of eight. Many command-line tools still render tabs at 8 by default, and reading a tab-indented file there makes deep nesting crawl off the right edge.

Modern editors often ship with 4 as the default because it reads better on screen. That's a preference baked into a default, not a standard. The same file opened in two editors with different tab-width settings looks different and is byte-identical.

Here's the practical consequence, and it's the failure case most guides skip. If a file mixes tabs and spaces for indentation, it can look correctly aligned in the author's editor and misaligned in a reviewer's. Python 3 turns that into a hard error rather than a cosmetic one, refusing to run code where indentation is inconsistent between tabs and spaces. Reviewers then see a diff that flags every line as changed even though the logic is untouched.

The fix is a project-level decision recorded somewhere durable. A .editorconfig file, supported by many editors, can declare indent_style = space and indent_size = 4 so every contributor's editor agrees. Without that file, tab width is a personal setting masquerading as a team standard.

How to Convert Tabs to Spaces in the Tools You Actually Use

Every mainstream editor has a built-in conversion, and using it beats counting spaces by hand. The exact names vary by version, so confirm the menu label on your installed build.

1: Notepad++: select the text, then Edit β†’ Blank Operations β†’ TAB to Space (or Space to TAB). Set the width first under Settings β†’ Preferences β†’ Language, where "Tab size" controls the conversion. 2: Visual Studio Code: open the Command Palette with Ctrl+Shift+P (Cmd+Shift+P on macOS) and run "Convert Indentation to Spaces." The status bar at the bottom right shows the current indentation mode and lets you click to change it. 3: Sublime Text: use View β†’ Indentation β†’ Convert Indentation to Spaces. The indentation width is set per-file in the same menu. 4: Microsoft Word: use Find and Replace. Type ^t in Find What and the desired number of spaces in Replace With. ^t is Word's code for a tab character in the Find field.

If the conversion looks wrong afterward, check the tab-width setting before converting β€” the tool uses that number, so a file set to 8 will gain eight spaces per tab. Run the conversion on a copy until you've confirmed the setting. For code, convert before committing, not after, so the diff stays readable.

Tabs vs. Spaces in Code: Where the Major Style Guides Land

Teams argue about this more than it deserves, but the guides are unusually explicit. Here's where the named authorities stand.

Style guide or language Indentation Tabs allowed? Notes
Google C++ Style Guide 4 spaces No Spaces only, per the guide's indentation section
Google Java Style Guide 4 spaces (2 for continuation) No Block indents are 4
PEP 8 (Python) 4 spaces per level No Mixing raises TabError in Python 3
Go (gofmt) Tabs Yes, required gofmt formats with tabs by default
Linux kernel coding style 8-character tabs Yes Documented by Linus Torvalds in the kernel's coding-style file
Ruby style guide (community) 2 spaces No Two-space convention is widespread

The split is real: Google's guides and PEP 8 forbid tabs, while Go's official formatter and the Linux kernel require them. Neither camp is being sloppy. Go ships gofmt, a formatter that makes the choice automatic, which removes the argument entirely β€” a lesson the other ecosystems haven't fully absorbed.

If your project has no stated rule, follow the files around you. Consistency inside a file matters more than which convention wins, because inconsistent indentation is the thing that actually breaks tooling and review.

The HTML and CSS Tab: One Space, Four Spaces, or a Collapsed Character

In HTML source, a tab character is whitespace and browsers collapse runs of whitespace to a single space when rendering. So a tab in your markup displays as one space in the page, regardless of how wide it looks in your editor. That's a rendering rule, not a width.

For visual indentation on the page itself, the CSS text-indent property is the right tool. A rule like p { text-indent: 2em; } indents the first line by two ems β€” a relative unit that scales with font size, which is why it's preferred over pixel values for prose. The element is the exception: inside it, whitespace is preserved exactly, so tabs and spaces keep their literal form.

The element you may remember from old HTML tutorials never existed in any specification. It's a persistent myth, and reaching for it wastes time. Use CSS.

For accessibility, note that indenting with spaces inside a paragraph can create odd screen-reader pauses in some configurations; CSS indentation avoids the problem because it's purely visual.

Word Processor Tabs: 0.5 Inches, Not Four Spaces

In Microsoft Word, pressing Tab moves the cursor to the next default tab stop, set at 0.5 inches. That's a physical distance, so the number of "spaces" it equals depends on your font and size. At 12-point Calibri, roughly 5 spaces fit in half an inch; at 11-point Arial, closer to 6.

You can change the interval under Format β†’ Paragraph β†’ Tabs, where you set the default tab stop and add custom stops with alignment (left, center, right, decimal) and optional leader characters like dots for a table of contents. Word also offers a first-line indent in the Paragraph dialog, which many style guides prefer over a literal tab.

For academic papers, the widely used APA Publication Manual (7th edition) calls for the first line of each paragraph to be indented 0.5 inches β€” a measurement, achievable with either a tab stop or paragraph formatting. Chicago Style similarly describes a half-inch first-line indent. Neither requires the tab character specifically.

Google Docs behaves the same way: the ruler's default tab stops are 0.5 inches, adjustable by dragging markers or via Format β†’ Tabs & indents.

Comparison Table: Tab Width by Context

Use this to find your number before you start converting.

Context Effective width Set or controlled by Convert with
Notepad++ default display 4 (configurable) Settings β†’ Preferences β†’ Language Edit β†’ Blank Operations
VS Code default display 4 (per-language overrides) Status bar indentation menu Command Palette conversion
Terminal / classic Unix tools 8 columns Tool's own default expand command
Google C++ and Java guides 4 spaces Style guide Editor formatter
PEP 8 (Python) 4 spaces Style guide; enforced by Python 3 Editor formatter
Go 1 tab gofmt gofmt
Linux kernel 8-character tab Kernel coding-style document Editor setting
Microsoft Word default tab stop 0.5 inches Paragraph β†’ Tabs dialog Find and Replace with ^t
HTML rendered whitespace 1 space Browser whitespace collapsing CSS text-indent

The 8-column Unix default and the 4-space code convention are the pair most often confused, and they produce visibly different files. Check which one your toolchain assumes before a bulk conversion.

Converting on the Command Line and the Cost of Getting It Wrong

Unix systems ship a utility called expand that converts tabs to spaces, and unexpand does the reverse. expand -t 4 file.txt writes the file with tabs replaced by spaces at 4-column intervals. The -t flag accepts a list of tab stops, so expand -t 4,8,12 sets three. These tools are named in the POSIX specification, which is why they're present on macOS and Linux by default.

The cost of a botched conversion shows up in version control. If a developer converts a 10,000-line file from tabs to spaces and commits it alongside a genuine fix, the diff marks all 10,000 lines as changed. A reviewer now has to find the real change inside the noise, and review time on that pull request multiplies. On a team merging twenty such requests a week, that's hours of avoidable work β€” a computation you can run on your own repository's line counts.

The safe pattern is a dedicated whitespace-only commit, reviewed quickly and recorded in the project's ignore-revs file so blame skips it. Git supports exactly this: git blame --ignore-revs-file lets you list commits to ignore, and a .git-blame-ignore-revs file at the repository root makes it the default for tools that respect it.

When It Actually Matters: Indentation-Sensitive Languages and Mixed Files

Python, YAML, and to a lesser degree Haskell treat indentation as syntax. In Python, a function body one level deeper than its def line is part of the function; the same lines at the wrong depth are a syntax error or, worse, a silent logic change. That's why PEP 8's ban on tabs matters beyond style β€” Python 3 raises TabError: inconsistent use of tabs and spaces in indentation rather than guessing.

YAML has the same exposure, and a tab character used for indentation in a YAML file is outright invalid per the YAML specification, which requires spaces. Configuration files edited by hand are a common source of this failure: a tab typed by accident in an indented block makes the file unparseable, and the error message often points a line or two away from the real problem.

Mixed-encoding files are the quieter edge case. Copying code out of a PDF or a chat window can introduce non-breaking spaces where ordinary spaces should be, which look identical on screen but break parsers. If a file "looks fine but won't run," check for non-ASCII whitespace before rewriting the indentation.

The practical rule: for indentation-sensitive formats, set your editor to insert spaces, turn on visible whitespace, and trust the project's configuration file over your own habits.

FAQ

Is a tab always equal to four spaces?

No β€” four is a common editor default, not a universal definition. Unix tools have historically rendered tabs at 8 columns, Microsoft Word uses a 0.5-inch physical tab stop, and HTML collapses tabs to a single rendered space, so the number depends on the software displaying the character.

Does Python allow tabs for indentation?

Python 3 permits tabs in principle but rejects files that mix tabs and spaces for indentation, raising TabError. PEP 8 recommends 4 spaces per level, and most teams enforce spaces through an editor configuration, which avoids the error class entirely.

How do I replace all tabs with four spaces in Word?

Open Find and Replace, put ^t in the Find What field, and type four spaces in Replace With. Check your ruler's tab stops first: if the document's tab stop is 0.5 inches and your font is large, four spaces won't align with the original indent.

Why does my code look misaligned when a colleague opens it?

Your tab-width display settings differ. The bytes on disk are the same, but an editor showing tabs at 8 columns will push deeply nested lines further right than one showing them at 4. An .editorconfig file pinning indent_size fixes the mismatch for every editor that supports it.

Can I convert tabs to spaces without an editor?

Yes β€” the POSIX expand utility does it from a terminal. expand -t 4 converts tabs to 4-column spacing, and unexpand reverses it. Both are standard on macOS and Linux, and Windows users can run them through Git Bash or WSL.

Is indenting with two spaces ever correct?

In some ecosystems, yes. Many Ruby and JavaScript projects use 2 spaces as a community convention, and Google's Java guide uses 2 spaces for continuation lines while keeping 4 for blocks. The file's existing style beats any general rule.

What does the HTML element do?

Nothing β€” it isn't a real element and never appeared in any HTML specification. For visual indentation in a web page, use CSS text-indent; for preserved whitespace in source, use the element.

Does a tab count as one character or several?

One. The tab is a single Unicode character, U+0009, which is why file sizes barely change when you convert to spaces β€” but a file with tabs replaced by four spaces will grow by roughly three bytes per indent level.