Menu

RTL layouts with CSS logical properties
📰

RTL layouts with CSS logical properties

DEV Community: frontend·Mohammad Khalifeh·13 days ago
#U276x5mg
#devtofrontend#devto#dev#left#start
Long article (466 words) — no AI summary yet.
Reading 0:00
15s threshold

Most stylesheets are written as if every reader reads left to right. Then a Persian or Arabic version is needed, and someone writes a second stylesheet full of [dir="rtl"] overrides that flip margins, paddings and floats. It works until the next feature ships and nobody remembers to add its override.

There is a simpler way. CSS has had logical properties for years, and every current browser supports them.

Physical vs logical

A physical property names a side of the screen: margin-left , padding-right , border-left . A logical property names a side of the text flow:

margin-inline-start is the side where a line starts. Left in English, right in Persian.

margin-inline-end is where a line ends.

margin-block-start and margin-block-end are the top and bottom in horizontal writing.

Set dir="rtl" on the html element and every logical property flips by itself.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.