tab-size CSS property

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since August 2021.

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

Try it

tab-size: 10px;
tab-size: 16px;
tab-size: 24px;
tab-size: 4;
<section id="default-example">
  <pre id="example-element">	123</pre>
</section>
#example-element {
  border: 1px solid;
}

Syntax

css
/* <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

<number>

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.

<length>

The width of tabs. Must be non-negative.

Formal definition

Initial value8
Applies toblock containers
Inheritedyes
Computed valuethe specified integer or an absolute length
Animation typea length

Formal syntax

tab-size = 
<number [0,∞]> |
<length [0,∞]>

Examples

Expanding by character count

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

Collapse tabs

css
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

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

css
p {
  white-space: pre;
}

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

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

Result

Specifications

Specification
CSS Text Module Level 3
# tab-size-property

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
tab-size
Chrome – Full support
Chrome 21 (Release date: 2012-07-31)
footnote
footnote This property is not yet animatable.
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote
footnote This property is not yet animatable.
Firefox – Full support
Firefox 4 (Release date: 2011-03-22)
prefix , footnote
prefix Implemented with the vendor prefix: -moz-
footnote Before Firefox 53, this property was not animatable.
Firefox – Full support
Firefox 91 (Release date: 2021-08-10)
footnote Full support
Opera – No support
Opera 10.5 – 12.1 (Release date: 2010-03-02)
prefix
prefix Implemented with the vendor prefix: -o-
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 7 (Release date: 2013-10-22)
footnote Full support
Chrome Android – Full support
Chrome Android 25 (Release date: 2013-02-27)
footnote
footnote This property is not yet animatable.
Firefox for Android – Full support
Firefox for Android 4 (Release date: 2011-03-29)
prefix , footnote
prefix Implemented with the vendor prefix: -moz-
footnote Before Firefox for Android 53, this property was not animatable.
Firefox for Android – Full support
Firefox for Android 91 (Release date: 2021-08-10)
footnote Full support
Opera Android – No support
Opera Android 11 – 12.1 (Release date: 2011-03-22)
prefix
prefix Implemented with the vendor prefix: -o-
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
footnote Full support
Safari on iOS – Full support
Safari on iOS 7 (Release date: 2013-09-18)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1.5 (Release date: 2013-09-25)
footnote
footnote This property is not yet animatable.
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote Full support
WebView on iOS – Full support
WebView on iOS 7 (Release date: 2013-09-18)
footnote Full support
<length>
Chrome – Full support
Chrome 42 (Release date: 2015-04-14)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 53 (Release date: 2017-04-19)
footnote Full support
Opera – Full support
Opera 29 (Release date: 2015-04-28)
footnote Full support
Safari – Full support
Safari 13.1 (Release date: 2020-03-24)
footnote Full support
Chrome Android – Full support
Chrome Android 42 (Release date: 2015-04-15)
footnote Full support
Firefox for Android – Full support
Firefox for Android 53 (Release date: 2017-04-19)
footnote Full support
Opera Android – Full support
Opera Android 29 (Release date: 2015-04-28)
footnote Full support
Safari on iOS – Full support
Safari on iOS 13.4 (Release date: 2020-03-24)
footnote Full support
Samsung Internet – Full support
Samsung Internet 4 (Release date: 2016-03-11)
footnote Full support
WebView Android – Full support
WebView Android 56 (Release date: 2017-02-01)
footnote Full support
WebView on iOS – Full support
WebView on iOS 13.4 (Release date: 2020-03-24)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
See implementation notes.
Requires a vendor prefix or different name for use.
Has more compatibility info.

See also