Skip to content

CSS Logical Properties and RTL: one stylesheet for Arabic and English pages

NeedMyTools Academy

Sign in free to read the full lesson

Sign in or create a free account

Free forever. No card, no paywall.

Arabic is read from right to left, and so are Urdu, Persian and Hebrew. When a site in the Gulf offers an Arabic version, the whole page should mirror: the logo moves to the right, the menu flows from the right, and the coloured bar on a quote box sits on the right edge where the reading starts. Old CSS was written in left and right, so developers copied the stylesheet and swapped every value by hand. Logical properties remove that work: you describe start and end, and the browser works out which side that is.

Quick answer

Set the direction in HTML with <html lang="ar" dir="rtl">, then write CSS with logical properties: margin-inline-start instead of margin-left, padding-inline for both sides, border-inline-start for a side bar, inset-inline-start for positioning and text-align: start. In a right-to-left page, "start" is the right side, so the same rules give a correct Arabic layout with no extra CSS. Flexbox and Grid already follow the direction.

25 min read and practice · Content checked on 5 November 2026

In this lesson you will

  • Set page direction correctly with the dir attribute, not with CSS
  • Explain the inline and block directions and how they map to left, right, top and bottom
  • Replace physical margins, padding, borders, positions and text alignment with logical ones
  • Mirror only the icons that point a direction, and keep numbers and code left to right

Direction belongs in HTML: the dir attribute

The direction of a page is part of its meaning, not its decoration, so it is set in HTML. <html lang="ar" dir="rtl"> tells the browser, search engines and screen readers that the page is Arabic and reads from right to left. The browser then lines up text on the right and lays out Flexbox rows and Grid columns from the right. The W3C internationalisation guide is clear: use the dir attribute on the html element, and do not rely on the CSS direction property for this.

Inside a page you can switch direction for one part. An English page that shows an Arabic customer review wraps it in <blockquote lang="ar" dir="rtl">. For text from users whose direction you do not know, such as names in a list, dir="auto" lets the browser decide from the first strong letter. The <bdi> element isolates a short piece, so an Arabic name inside an English sentence does not scramble the punctuation around it.

Try it: The same HTML in both directions
Code
ResultUpdates as you type
Console
  1. Console messages, errors, form data and clicked links appear here.

Both bars use the same CSS. Only dir changes, and the Flexbox row starts from the left in one and from the right in the other.

Sign in free to read the full lesson

You are reading the free preview. Create a free account (it takes one minute, no password) to unlock the rest of this lesson and track your progress.

Unlocks after sign-in:

  • 3 more sections with live code examples
  • Common mistakes to avoid
  • Hands-on coding exercise with automatic checks
  • Practice quiz and the graded lesson test
Sign in or create a free account

Free forever. No card, no paywall.

Questions people ask

What are CSS logical properties?

They are versions of margin, padding, border, size and position properties that use start and end instead of left, right, top and bottom. The browser maps them to physical sides from the page’s writing direction, so one rule works for English, Arabic and other scripts.

How do I make a website support Arabic right to left?

Add lang="ar" and dir="rtl" to the html element of the Arabic pages, write your CSS with logical properties, use a font stack with an Arabic font, keep numbers and code in dir="ltr", and mirror only directional icons. Then test every page with real Arabic text.

Do Flexbox and Grid change in RTL pages?

Yes, automatically. A row starts from the right, flex-start means the right side and Grid column 1 is on the right. You only need to check places where you used physical values such as left, margin-right or translateX().

Is text-align: start the same as text-align: left?

Only in left-to-right text. start aligns to wherever the line begins, so it is the left in English and the right in Arabic. It is also the browser default, so in many cases you can remove text-align: left instead of replacing it.

Can I use logical properties in all browsers?

The ones in this lesson, such as margin-inline, padding-inline-start, border-inline-start and inset-inline-end, work in every current version of Chrome, Edge, Safari and Firefox. Only very old browsers that no longer get security updates lack them.

Sources

Facts in this lesson were checked against these official pages on 5 November 2026.

Code examples stay in English and run in a sandbox on your device. If you spot a mistake, tell us through the contact page.