CSS tab-size Property

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The tab-size property sets the rendered width of each tab character (U+0009). A number means that many space widths. A length such as 2em sets an absolute width.

It is most useful on <pre> and code samples where tabs are preserved. Pair it with white-space: pre, pre-wrap, or break-spaces. The property is inherited. The initial value is 8.

Baseline · Widely available.

Not deprecated. Older Firefox used the prefix -moz-tab-size; modern browsers use unprefixed tab-size.

CSS Syntax

syntax.css
tab-size: <number> | <length>;

Example: tab-size: 4; or tab-size: 2em;. Values must be non-negative.

Property Values

ValueDescriptionTry it
<number>Tab width in multiples of a space (default 8)Try it
<length>Absolute tab width such as 16px or 2emTry it
0Tabs take no widthTry it
initialResets to 8Try it
inheritTakes the parent’s tab-sizeTry it

How to Use tab-size

Preserve tabs in the markup, then set how wide each tab should look.

  1. Use a <pre> (or set white-space: pre / pre-wrap).
  2. Put real tab characters in the text (not only spaces).
  3. Set tab-size to a number (common: 2 or 4) or a length.
  4. Optional: use a monospace font-family so columns line up clearly.
PieceRequired?Role
Preserved whitespaceYespre / pre-wrap / break-spaces
Tab characters in contentYesSpaces alone are not affected
Number or lengthYesHow wide each tab renders

Live Preview

The sample uses a real tab before each number. Change tab-size and watch the indent change.

Default is 8. Many editors prefer 2 or 4 for code.

Sample
	123
		456
			789

tab-size: 4

CSS Examples

Each snippet focuses on tab-size. Extra styles stay minimal for study. Use Try It Yourself for a live editor.

Example 1 — Four-Space Tabs

A common code style: each tab looks four spaces wide.

CSS
<style>
  pre {
    tab-size: 4;
  }
</style>

<pre>	line
		nested</pre>
Try It Yourself

How It Works

  1. Use pre. It keeps tab characters instead of collapsing them.
  2. Set a number. tab-size: 4 makes each tab four space-widths wide.
  3. Count levels. One tab indents once; two tabs indent twice.
  4. Not spaces. If the file used spaces instead of tabs, nothing would change.

Example 2 — Length Value

Set an absolute tab width with a length unit.

CSS
<style>
  pre {
    tab-size: 2em;
  }
</style>

<pre>	line
		nested</pre>
Try It Yourself

How It Works

  1. Use a length. 2em is relative to the element’s font size.
  2. Not space-counting. Unlike 4, this is not “four spaces” — it is a fixed measure.
  3. Scales with font. Larger type makes each tab wider when you use em.
  4. Same content. Still needs real tab characters in the pre.

Example 3 — Zero Width Tabs

Collapse tab width to nothing with tab-size: 0.

CSS
<style>
  pre {
    tab-size: 0;
  }
</style>

<pre>	line
		nested</pre>
Try It Yourself

How It Works

  1. Zero is valid. Non-negative numbers include 0.
  2. No indent. Tabs still exist in the text, but they take no horizontal space.
  3. Compare with 4. Switch to Try It Yourself and change 0 to 4 to see the difference.
  4. Rare in UI. Most code samples use 2 or 4, not 0.

Edge Cases & Pitfalls

If tabs look unchanged, one of these is usually why.

spaces

Only real tabs count

tab-size ignores indentation made with space characters. The content must contain U+0009 tabs.

ws

Needs preserved whitespace

With default white-space: normal, tabs collapse. Use pre, pre-wrap, or break-spaces.

html

Editors may convert tabs to spaces

Many editors insert spaces on Tab. Check that the file actually stores tab characters.

neg

Negative values are invalid

Only non-negative numbers and lengths are allowed. Invalid values are ignored.

prefix

Old -moz-tab-size

Unprefixed tab-size is enough for modern browsers. Keep the prefix only if you must support very old Firefox.

Browser Support

tab-size is a browser CSS property for rendering tab characters. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

tab-size

Chrome 42+, Edge 79+, Firefox 91+, Safari 13.1+ / iOS 13.4+. Not supported in Internet Explorer.

97% Global support
Google Chrome 42+
Full support
Mozilla Firefox 91+
Full support
Apple Safari 13.1+
Full support
Microsoft Edge 79+
Full support
Opera 29+
Full support
Samsung Internet 4+
Full support
Internet Explorer No support
No support
tab-size Widely supported

Bottom line: Safe for modern sites. Prefer unprefixed tab-size. This is not a JavaScript runtime API.

Key Takeaways

  • Role: set how wide each tab character renders — number of spaces or a length.
  • Initial: 8. Common code values are 2 and 4.
  • Needs tabs + pre whitespace. Spaces alone and white-space: normal hide the effect.
  • Inherited. Set once on a code container to style nested lines.

One line: tab-size controls tab width in preformatted text — not regular space indentation.

Frequently Asked Questions

It sets how wide each tab character (U+0009) is rendered. A number means that many space widths. A length such as 2em sets an absolute tab width.
The initial value is 8, so each tab is as wide as eight space characters unless you change it.
When tab characters are preserved — typically in a pre element, or with white-space: pre, pre-wrap, or break-spaces. With the default white-space: normal, tabs collapse and you will not see the effect.
No. It only affects real tab characters in the text. Indentation made with space characters is unchanged.
Yes. tab-size: 0 is valid and makes tabs take no width.
It is Baseline Widely available: Chrome 42+, Edge 79+, Firefox 91+, Safari 13.1+. It is a browser CSS property, not a Node.js feature. Internet Explorer does not support it.

Next: table-layout

Choose fixed or automatic algorithms for table column widths.

table-layout tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful