Faulty logic
Tags: css, logical, properties, browsers
Published: 2021-12-10 20:44:29

---
title: Faulty logic
published: true
date: 2021-11-24 14:03:46 UTC
tags: css,logical,properties,browsers
canonical_url: https://adactio.com/journal/18640
---

I’m a fan of [logical properties](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Logical_Properties) in CSS. As I wrote in the responsive design course on web.dev, [they’re crucial for internationalisation](https://web.dev/learn/design/internationalization/).

Alaa Abd El-Rahim has written articles on CSS tricks about [building multi-directional layouts](https://css-tricks.com/building-multi-directional-layouts/) and [controlling layout in a multi-directional website](https://css-tricks.com/control-layout-in-a-multi-directional-website/). Not having to write separate stylesheets—or even separate rules—for different writing modes is great!

More than that though, I think understanding logical properties is the best way to truly understand CSS layout tools like grid and flexbox.

It’s like when you’re learning a new language. At some point your brain goes from _translating_ from your mother tongue into the other language, and instead starts _thinking_ in that other language. Likewise with CSS, as some point you want to stop _translating_ “left” and “right” into “inline-start” and “inline-end” and instead start _thinking_ in terms of inline and block dimensions.

As is so often the case with CSS, I think new features like these are easier to pick up if you’re new to the language. I had to unlearn using floats for layout and instead learn flexbox and grid. Someone learning layout from scatch can go straight to flexbox and grid without having to ditch the cognitive baggage of floats. Similarly, it’s going to take time for me to shed the baggage of directional properties and truly grok logical properties, but someone new to CSS can go straight to logical properties without passing through the directional stage.

Except we’re not quite there yet.

In order for logical properties to replace directional properties, they need to be implemented everywhere. Right now you can’t use logical properties inside a media query, for example:

```
@media (min-inline-size: 40em)

```

That wont’ work. You have to use the old-fashioned syntax:

```
@media (min-width: 40em)

```

Now you could rightly argue that in this instance we’re talking about the _physical_ dimensions of the viewport. So maybe width and height make more sense than inline and block.

But then take a look at how the syntax for [container queries](https://web.dev/learn/design/micro-layouts/#container-queries) is going to work. First you declare the axis that you want to be contained using the syntax from logical properties:

```
main {
  container-type: inline-size;
}

```

But then when you go to declare the actual container _query_, you have to use the corresponding directional property:

```
@container (min-width: 40em)

```

This won’t work:

```
@container (min-inline-size: 40em)

```

I kind of get why it won’t work: the syntax for container queries should match the syntax for media queries. But now the theory behind disallowing logical properties in media queries doesn’t hold up. When it comes to container queries, the physical layout of the viewport isn’t what matters.

I hope that both media queries and container queries will allow logical properties sooner rather than later. Until they fall in line, it’s impossible to make the jump fully to logical properties.

There are some other spots where logical properties haven’t been fully implemented yet, but I’m assuming that’s a matter of time. For example, in Firefox I can [make a wide data table responsive](https://codepen.io/adactio/pen/ZEJvavz) by making its container side-swipeable on narrow screens:

```
.table-container {
  max-inline-size: 100%;
  overflow-inline: auto;
}

```

But [`overflow-inline`](https://caniuse.com/mdn-css_properties_overflow-inline) and [`overflow-block`](https://caniuse.com/mdn-css_properties_overflow-block) aren’t supported in any other browsers. So I have to do this:

```
.table-container {
  max-inline-size: 100%;
  overflow-x: auto;
}

```

Frankly, mixing and matching logical properties with directional properties feels worse than not using logical properties at all. The inconsistency is icky. This feels old-fashioned but consistent:

```
.table-container {
  max-width: 100%;
  overflow-x: auto;
}

```

I don’t think there are any particular technical reasons why browsers haven’t implemented logical properties consistently. I suspect it’s more a matter of priorities. Fully implementing logical properties in a browser may seem like a nice-to-have bit of syntactic sugar while there are other more important web standard fish to fry.

But from the perspective of someone trying to _use_ logical properties, the patchy rollout is frustrating.