tab-size
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;
123
#example-element {
border: 1px solid;
}
Syntax
css
/* values */
tab-size: 4;
tab-size: 0;
/* 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
Formal definition
Initial value | 8 |
---|---|
Applies to | block containers |
Inherited | yes |
Computed value | the specified integer or an absolute length |
Animation type | a length |
Formal syntax
tab-size =
|
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
no tab
default tab size of 8 characters wide
custom tab size of 3 characters wide
3 spaces, equivalent to the custom tab size
custom tab size of 50px wide
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 |