tab-size
Widely availableSince 202197% of users
Controls the width of tab characters in code/preformatted text. Specify as a number of spaces or a length.
What's modern
From web-features, MDN's browser data and our snippets, checked dailyModernIn every major browser since August 2021. Widely available since February 2024.
See how modern your own CSS is.Check your CSS →
Quick facts
- Initial value
8- Inherited
- Yes
Quick example
pre { tab-size: 2; }
code { tab-size: 4; }Syntax
<integer> | <length>Examples
Make tab characters wider
pre {
tab-size: 8;
/* Each tab takes up 8 character widths */
}Control how many spaces a tab character represents in preformatted text.
Standardize code display
code, pre {
tab-size: 4;
font-family: 'Courier New', monospace;
}Use tab-size to match your code editor's tab width for consistent display.
Common pitfalls
- Only works with white-space: pretab-size only affects how tabs display in pre, code, or elements with white-space: pre. Regular text ignores tabs anyway.
- Measured in character widths, not pixelstab-size: 4 means 4 character widths, not 4 pixels. The actual width depends on the font and font-size.
tab-size browser support
BaselineWidely availableThis feature is well established and works across many devices and browser versions. It has been available across browsers since 2021.Safe to use without fallbacks.
Usage97%of people can use this3% use a browser without it.
Browsers
21+
91+
7+
79+Mobile
25+Android
91+Android
7+iOS