Web Development

CSS Logical Properties: Easy RTL & LTR Layouts

MVP consulting firm UK

November 12, 2026

MVP consulting firm UK

5 min read

This article was originally published by Dzmitry Hutaryan on dev.to in December 2023 and is republished here with the author's permission.

CSS Logical Properties: Build RTL-Ready Layouts Without Extra Code

Sometimes we have to support multi language app. Some of them might have a different direction, form left to right. But how to keep our margins/padding the same? I know there are some tools for that, but actually there is a native solution.

Today we are going to talk about logical css properties:

These properties are similar to usual properties but with special sense.

Example 1: Margins and padding that follow text direction

Let's say we have a container with padding: 20px 60px 80px 10px; (top right bottom left). Then we add direction: rtl; to change language direction. We will see that our right padding is 60px but we need 10px as before left padding was.

That's why we need logical properties.

If we use logical properties out paddings will be changed with text direction as well. In this case right padding 60px will become 10px and vice versa. It works the same for writing-mode: vertical-rl;

Image description

You can play with margins on the codepen at the end of article.

Example 2: Logical borders

I guess it's clear for margins and paddings. But these properties work for borders as well.

Let's see the difference for left to right direction.

Image description

Example 3: Positioning with inset-inline and inset-block

Only one type of property has left. As you might already guess inset-block/inset-inline allow us to apply logical properties for elements with absolute positioning.

When we have element with position: absolute; and use usual properties we won't see any changes. But if we use inset-block/inset-inline and change text direction we will se how position of element will be changed as well.

Bonus: Centering with one line

Now, you know how to show element by center using one row of css.

FAQ

What’s the difference between logical and physical CSS properties?

Physical properties (left, right, top, bottom) refer to fixed sides of the screen. Logical properties (inline-start, block-end, etc.) refer to the direction of content, so they adapt to RTL and vertical writing modes.

Do I still need an RTL stylesheet if I use logical properties?

Usually not for spacing, borders and positioning. You may still need tweaks for icons with directional meaning (like arrows) and for some transforms.

How do I set the direction of a page?‍

Use the HTML attribute dir="rtl" on <html> or a container, rather than the CSS direction property. It’s semantically correct and also helps screen readers and search engines.

Are CSS logical properties safe to use in production?‍

Yes. They’re supported across all modern browsers.

Rapid PoC for tech product UK

suBscribe

to our blog

Subscribe
MVP consulting firm UK
Thank you, we'll send you a new post soon!
Oops! Something went wrong while submitting the form.