Firefox Tomorrow

css property

`tab-size` CSS property

View on MDN ↗

The tab-size CSS property is used to customize the width of tab characters (U+0009).

Interactive exampleOpen the canonical MDN source to run this embedded demo.
tab-size: 10px;
tab-size: 16px;
tab-size: 24px;
tab-size: 4;
<section id="default-example">
  <pre id="example-element">&#9;123</pre>
</section>
#example-element {
  border: 1px solid;
}

Syntax

/* <number> values */
tab-size: 4;
tab-size: 0;

/* <length> values */
tab-size: 10px;
tab-size: 2em;

/* Global values */
tab-size: inherit;
tab-size: initial;
tab-size: revert;
tab-size: revert-layer;
tab-size: unset;

Values

  • &lt;number&gt;
    • : A multiple of the advance width of the space character (U+0020) to be used as the width of tabs. Must be non-negative. The advance width means the distance a cursor or a print head moves before printing the next character.
  • &lt;length&gt;
    • : The width of tabs. Must be non-negative.

Formal definition

Formal syntax

Examples

Expanding by character count

pre {
  tab-size: 4; /* Set tab size to 4 characters wide */
}

Collapse tabs

pre {
  tab-size: 0; /* Remove indentation */
}

Default tab size vs custom sizes

This example compares a default tab size with a custom tab size. Note that white-space is set to pre to prevent the tabs from collapsing.

HTML

<p>no tab</p>
<p>&#0009;default tab size of 8 characters wide</p>
<p class="custom-number">&#0009;custom tab size of 3 characters wide</p>
<p>&nbsp;&nbsp;&nbsp;3 spaces, equivalent to the custom tab size</p>
<p class="custom-length">&#0009;custom tab size of 50px wide</p>

CSS

body {
  border: 1px solid red;
  margin: 1rem;
}
p {
  white-space: pre;
}

.custom-number {
  tab-size: 3;
}

.custom-length {
  tab-size: 50px;
}

Result

Interactive exampleOpen the canonical MDN source to run this embedded demo.

Specifications

SpecificationsStandards references are available on the canonical MDN page.

Browser compatibility

Browser compatibilityCompatibility data is available on the canonical MDN page.

See also