Why it matters
- Phone numbers are the usual victim. Inside Arabic text,
+966 50 123 4567can appear as4567 123 50 966+, so a visitor who reads the number off the screen dials the wrong one. - This is the browser following the Unicode Bidirectional Algorithm: the digits of each group stay left to right, but the groups, separated by spaces, follow the right-to-left direction of the paragraph. Names such as
C++andC#lose their symbols to the other side of the word in the same way. - The page looks right to its author only when the number sits on its own: the problem appears once the number is placed inside an Arabic sentence.
Example
<p>اتصل بنا على +966 50 123 4567 من الأحد إلى الخميس.</p> <p>نطوّر أنظمة المخازن بلغة C++ منذ عشر سنوات.</p>
<p> اتصل بنا على <a href="tel:+966501234567" dir="ltr">+966 50 123 4567</a> من الأحد إلى الخميس. </p> <p>نطوّر أنظمة المخازن بلغة <bdi>C++</bdi> منذ عشر سنوات.</p>
How to fix
Mark the number or the word as left to right:
html
<p>اتصل بنا على <a href="tel:+966501234567" dir="ltr">+966 50 123 4567</a></p>
<p>نطوّر أنظمة المخازن بلغة <bdi>C++</bdi></p>- Use
dir="ltr"when the text is always left to right, like a phone number. - Use
<bdi>when the direction is not known in advance, such as names or codes from a database. - Where markup is not possible, as in a page title, put the invisible left-to-right mark
U+200Eon both sides of the number.
How we detect
- We render the page in a browser. In each element laid out right to left, we look for numbers made of groups separated by spaces or hyphens, and phone numbers written with
+and at least 8 digits, in Western or Arabic-Indic digits, and for Latin words that end in+or#. A short number after+, such as+500for "more than 500", reads as meant either way, so it does not count. - For each one, we measure where the browser drew each of its characters. When a character sits to the left of the one written before it, on the same line, the number or word is out of order. Those split over two lines are not checked.
- The finding shows the number or the word as written, and the element that holds it.