CSS Portal

CSS tab-size Property

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The tab-size CSS property controls the width used to display tab characters (U+0009) within rendered text. Rather than altering the tab characters themselves, it determines how many character columns a tab counts for when the browser computes tab stops and aligns following content. This affects visual layout in any text that contains literal tab characters — commonly seen in source code blocks, preformatted text, or data pasted from plain-text sources — and helps preserve or adjust alignment without changing the underlying text.

Rendering of tab characters with tab-size is influenced by the text flow: tabs create tab stops that the renderer advances to, so the placement of subsequent characters depends on the tab stop grid which is derived from the computed tab width and the start of the current line. That behavior interacts with whitespace handling and line wrapping rules; for example, the way a tab is preserved or causes wrapping depends on the surrounding whitespace policy as controlled by white-space. The visual width of a tab is also ultimately measured in terms of the current font metrics, so the effective on-screen spacing will vary with typography choices such as font-family and font-size, which can make a given tab-size look wider or narrower in different contexts.

Practical uses of tab-size include keeping columns aligned in code listings or plain-text tables, improving legibility of pasted logs, or matching the tab width expected by a codebase or editor without rewriting files. For accessibility and consistency, many projects prefer converting tabs to spaces at a canonical width before display, but when you must render raw tabs, adjusting tab-size lets you control visual alignment on the page. Keep in mind that changing tab rendering affects layout only — it does not modify the document text or how assistive technologies expose content, so it's a purely visual tuning mechanism.

Definition

Initial value
8
Applies to
block containers
Inherited
Yes
Computed value
the specified integer or an absolute length
Animatable
a length
JavaScript syntax
object.style.tabSize

Interactive Demo

	Tab Size Demo

Syntax

tab-size: <integer> | <length>

Values

  • <integer>The number of spaces in a tab. Must be positive value.
  • <length>The width of a tab. Must be positive value.

Example

<div class="container">
<h1>tab-size examples</h1>

<div class="example">
<h2>default (browser)</h2>
<pre class="sample default">Item1 Item2 Item3
LineA LineB LineC</pre>
</div>

<div class="example">
<h2>tab-size: 2</h2>
<pre class="sample two">Item1 Item2 Item3
LineA LineB LineC</pre>
</div>

<div class="example">
<h2>tab-size: 4</h2>
<pre class="sample four">Item1 Item2 Item3
LineA LineB LineC</pre>
</div>

<div class="example">
<h2>tab-size: 8</h2>
<pre class="sample eight">Item1 Item2 Item3
LineA LineB LineC</pre>
</div>
</div>
/* Basic layout */
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
  background: #f6f8fa;
  color: #0f172a;
  padding: 24px;
}

/* Container */
.container {
  max-width: 760px;
  margin: 0 auto;
}

/* Sample block */
.sample {
  display: block;
  white-space: pre;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, "Roboto Mono", "Courier New", monospace;
  background: #ffffff;
  border: 1px solid #e6e8eb;
  padding: 12px 14px;
  border-radius: 6px;
  margin-top: 8px;
  overflow: auto;
}

/* Different tab sizes */
.sample.two {
  tab-size: 2;
  -moz-tab-size: 2;
}

.sample.four {
  tab-size: 4;
  -moz-tab-size: 4;
}

.sample.eight {
  tab-size: 8;
  -moz-tab-size: 8;
}

/* Headings */
h1 {
  font-size: 18px;
  margin: 0 0 12px;
}

h2 {
  font-size: 14px;
  margin: 16px 0 6px;
  font-weight: 600;
}

Browser Support

The following information will show you the current browser support for the CSS tab-size property. Hover over a browser icon to see the version that first introduced support for this CSS property.

This property is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 1st January 2026

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!