Why it matters
- In a right-to-left field, the groups of a phone number are laid out from right to left: the country code moves to the end, and the groups swap places. People think they typed it wrong, and change a number that was right.
- Chromium, Firefox and WebKit, Safari's engine, show
type="tel"fields left to right on right-to-left pages, but phone fields written astype="text", even withinputmode="tel", take the page's direction.
Example
<label for="phone">رقم الجوال</label> <input id="phone" name="phone" inputmode="tel" autocomplete="tel" />
<label for="phone">رقم الجوال</label> <input id="phone" name="phone" type="tel" dir="ltr" autocomplete="tel" />
How to fix
- Use
type="tel"for phone fields, which also opens the phone keypad, and adddir="ltr"so every browser shows the number left to right:<input type="tel" dir="ltr" autocomplete="tel">. - To keep the field aligned with the right-to-left page, add
text-align: rightto it in CSS. dir="auto"works too: the field takes its direction from what is typed.
How we detect
- We render the page and read the computed direction of each text field, in each engine.
- A phone field is one with
type="tel",inputmode="tel"or anautocompletefor a phone number, or whose name, id, label or placeholder names a phone («هاتف»، «جوال»، «واتساب», phone, mobile…). - It fails when it is shown right to left without
dir="auto"orunicode-bidi: plaintext. Number fields (type="number") are left out: they hold digits alone, which keep their order.