Why does a date reverse itself inside an Arabic line?
I was rendering a check timestamp inside an Arabic sentence:
<span>فُحص</span> 2026-08-04 13:10
On screen, the time showed up before the date.
Nothing about the text had changed. The characters were exactly the ones I typed; only the rendering order moved.
The cause
Browsers run every line through the bidirectional algorithm. An Arabic paragraph flows right to left, while digits always run left to right.
The space sitting between the date and the time is a neutral character, so it inherits direction from its context, and here the context is an Arabic paragraph.
That turns the date and the time into two separate left-to-right islands inside a right-to-left line, and the algorithm lays out the second island first.
The fix
Wrap both parts in a single isolated unit:
<span>فُحص</span>
<bdi dir="ltr">2026-08-04 13:10</bdi>
<bdi> stands for bidirectional isolate, and HTML added it for exactly this situation. Whatever sits inside is laid out on its own: the surrounding paragraph cannot reorder it, and it cannot disturb the paragraph.
Why not use dir="ltr" on the paragraph
Because on an Arabic page that left-aligns the entire paragraph. You trade a reversed timestamp for a broken layout. Scope the isolation to the number itself and leave the line alone.
Where this shows up most
Anywhere Arabic copy carries numbers with internal separators: dates and times, phone numbers, IBANs, order references, version numbers, IP addresses.
The rule
Wrap every composite number inside Arabic text in <bdi>. Add the wrapper before anyone reports the bug: a reversed date on an admin screen is an annoyance you can live with, while the same reversal on an invoice or a bank transfer carries far heavier consequences.
Related reading
Tell me what you want to build. Your first 15 minutes of consulting are free.
Book a consultation