Artboard 16light, inspiration, solution, idea, innovation,ionicons-v5_logosGoogle Sheets iconSwift icon
Published at
Updated at
Reading time
2min
This post is part of my Today I learned series in which I share all my web development learnings.

Slowly but surely, developers adopt logical CSS properties to be good web citizens and write CSS that follows a defined writing mode, directionality, and text orientation.

width becomes inline-size, margin-inline is a shorthand for margin-left and margin-right, you get the idea.

MDN lists all the logical CSS properties if you haven't heard about them yet.

That's all good and dandy, but there's at least one situation where logical CSS properties aren't enough. Suppose you want to style a container and make it 50% of the viewport on the horizontal axis.

You can define inline-size: 50vw; but isn't that mixing things up? inline-size will define either the horizontal or vertical size depending on the writing mode, but 50vw will always be the viewport width.

I don't know if that's a real issue because I can't read languages that go from top to bottom, let alone build a website. But I can imagine that writing mode dependent viewport units can be handy!

And today I learned these viewport units exist! vi and vb consider writing direction!

vi is the percentage of the initial containing blocks inline axis and vb the percentage of the block axis. ๐Ÿคฏ

In left-to-right
vi -> vw
vb -> vh

---

In top-to-bottom
vi -> vh
vb -> vw

That's confusing stuff, so I build a component to learn how this works!

Playground
Choose a writing mode
Choose size properies
Choose a unit type
.๐Ÿ‘‹ {
  writing-mode: horizontal-tb;
  width: 50vw;
  height: 20vh;
}
Preview
Inline Axis
Block Axis

Text is lined out horizontally and flows from top to bottom.

The container's horizontal size is 50% viewport width and its vertical size is 20% viewport height.

There's nothing fancy here. It's pretty much the default.

What's the browser support? Chrome started supporting these units not very long ago.

MDN Compat Data (source)
Browser support info for vi unit
chromechrome_androidedgefirefoxfirefox_androidsafarisafari_iossamsunginternet_androidwebview_android
10810810810110115.415.4Nein108

I'm no expert in languages other than German and English, but are people building Asian websites ecstatic about these units and that they're almost cross-browser supported at the time I'm publishing this article?

If you know more about it, I'd love to hear more!

Was this TIL post helpful?
Yes? Cool! You might want to check out Web Weekly for more quick learnings. The last edition went out 3 days ago.

Related Topics

Related Articles