Definition
- Arabic, Persian, Urdu and Hebrew are written from right to left: each line starts at the right edge.
- A page declares it in HTML with
dir="rtl"on<html>. CSS has adirectionproperty, but the W3C and the HTML and CSS standards ask for the attribute: direction is part of the text's meaning, and must hold where styles do not apply. - The base direction also sets the default text alignment, the order of table columns, the direction of horizontal overflow, and the order of Arabic and Latin runs in a paragraph.
Why it matters
- Without a declared direction, an Arabic page is laid out left to right: lines start on the left, a sentence's final punctuation moves to its start, and numbers and English words land in the wrong places.
dir="rtl"on<body>alone does not reach the elements outside it, such as<title>.- Left-to-right themes keep their physical sides: a menu hidden past the left edge, the side a right-to-left page scrolls toward, can widen the page on a phone.
Example
Direction and language on the root, and the other direction only where needed:
html
<html lang="ar" dir="rtl">
<body>
<h1>سياسة الخصوصية</h1>
<p lang="en" dir="ltr">This policy is also available in English.</p>
</body>
</html>Common mistakes
- Setting the direction with CSS
direction: rtlalone: it is lost where styles do not apply, such as a reader mode. dir="auto"on the whole page: the browser takes the direction from the first strong letter, so a page starting with a Latin brand name turns left to right.- Keeping
text-align: leftandmargin-leftfrom an English theme, instead oftext-align: startandmargin-inline-start. - "Next" arrows pointing right: forward in Arabic is to the left, and browsers do not mirror icons.