Did you know that you can use tab stops in HTML? In this article I want to explore this ancient typographic concept and see how it can be used on the web.
What are tab stops?
Somehow the word ātabā is extremely overloaded in tech. We have browser tabs, tabbed interfaces in general, tab keys, we tab between form fields⦠but what I want to talk about are tab stops.
Tab stops. The way youād use them in a word processor; its name originating from mechanical gears in typewriters that would stop the carriage at certain positions when the tab key is pressed.


Making tab stops visible
Insert a tab character (U+0009) in your HTML, and it looks just like a space. In fact, thatās a tab character between āaā and āspaceā. Boring!
But wait, if you prevent collapsing white-space with the white-space property, tabs become visible. By default, HTML collapses all white-space characters. Setting white-space: pre preserves these characters, including tabs.
Now
and
And wow, they are not just wide spaces! The width of a single tab stop depends on the text before it.
Interactive demo
Hereās an interactive demo where you can play around with tab stops and their size:
The width
It
Two CSS properties make this work. The first is the aforementioned white-space to preserve the tab characters:
white-space: pre;
You could set it on the parent element, but this will preserve all kinds of white space in there. Not want we want. The trick is wrapping just the tab character in a span and applying the magic there. This way the rest of the text behaves normally.
The second property is tab-size, which defines how wide a tab stop is:
tab-size: 8; /* default (8 spaces) */
tab-size: 2rem; /* okay */
tab-size: 50cqw; /* huh? */
The tab-size property accepts any length unit, and here I used cqw which is relative to the containerās width:
.tab-stops-demo {
container-type: inline-size;
}
tab-stop {
white-space: pre;
tab-size: 50cqw; /* Tab jumps to 50% of container width */
}
For this article Iāve built a tiny web component that inserts a tab character and applies all of these styles:
This text <tab-stop></tab-stop> has tab stops.
This <tab-stop size="12"></tab-stop> is a tab stop with custom size.
Ancient technology meets modern CSS!
Donāt try this at home
Donāt get me wrong, this is extremely experimental. Tabs arenāt responsive in any traditional sense and the alignment can break on smaller screens. Iād have to test how different screen readers treat tab stops. And how do users even input tabs in a CMS when the tab key navigates between fields? Maybe a separate button?
For actual layouts flex or grid are obviously a better pick. For tabular (āconsisting of or presented in columns or tablesā) data, use a <table>, duh. But maybe thereās a use case for this, who knows?
If Iāll ever find a use case, Iāll document it here:
Replies
-
I've also added a replies section to my articles. Replies to my Mastodon posts are displayed automatically š¤
-
@medienbaecker curious what kind of solution is used to link Mastodon replies to post? Is it open source
-
@asci Itās actually just a very simple version of https://blog.thms.uk/2023/02/mastodon-comments
In the backend I add the Mastodon post URL to articles, everything else is in handled in the frontend. I can share the details in a future article if youāre interested š -
@medienbaecker Maybe thereās some use case for this in typesetting poetry?
-
@pb Thatās a great idea, Philipp! Iāll have to reach out to an old client of mine for this use case; a perfect example: https://www.praeposition.com/text/archiv/sentimenthek/65-pier-paolo-pasolini-ragazzi-di-vita
-
@medienbaecker Love the little thingsāthe space in the sharing image, the āsurprise, the previous sentence contained a tabā, and also the live demo.
Really wonder what the intent was in adding these to the standardāif they just felt like it just had to be there, of it it made more sense back in the day!
-
@Cykelero Thanks for the kind feedback, Nathan! Yeah, I think itās definitely one of these features reminding us of the ātext document with hyperlinksā past of the web.