---
title: "What is right-to-left (RTL) text? Bidi for Arabic AI apps"
description: "RTL text such as Arabic is stored in logical order and displayed by the Unicode Bidirectional Algorithm. How bidi works and how to show LLM output safely."
url: https://broadrouter.com/glossary/rtl-text/
lang: en
updated: 2026-11-15
publisher: BroadRouter (a BroadNet site); API by BroadNet Inference, https://inference.broadnet.ai
---

# Right-to-left (RTL) text

Updated 2026-11-15

Right-to-left (RTL) text is writing, such as Arabic or Hebrew, displayed from right to left. Computers store it in logical reading order, and the Unicode Bidirectional Algorithm decides display order when RTL text mixes with left-to-right text, digits, model names or code.

Also called: RTL, right-to-left, bidirectional text, bidi

The model’s Arabic answer is correct, but on screen the price sits on the wrong side and the model name is broken in half. That is a bidi problem, not a model problem.

## How it works

Text is stored in logical order, the order it is read and typed. UAX #9, the Unicode Bidirectional Algorithm, assigns each character a direction type and works out display order for the line. Characters never move in memory; only their display changes.

Letters are strong: Arabic is right-to-left, Latin is left-to-right. Digits and punctuation are weak or neutral and take their position from the text around them. European digits are type EN and Arabic-Indic digits type AN, and UAX #9 resolves EN to AN after an Arabic letter.

A typical mixed string from an Arabic assistant:

```text
جرّب النموذج broadnet/qwen3.8-27b على 20 رسالة
```

Displayed in a left-to-right context, the Arabic runs read right to left but the paragraph starts on the left, so the sentence appears in the wrong order and the slash, dots and the number 20 can attach to the wrong run. The fix is to set the base direction, not to reorder characters.

When markup is not available, Unicode has invisible control characters:

| Code point | Name | Use |
| --- | --- | --- |
| U+200F | RLM, right-to-left mark | Nudge a neutral character to RTL |
| U+061C | ALM, Arabic letter mark | Same, for Arabic contexts |
| U+2067 | RLI, right-to-left isolate | Start an RTL span |
| U+2066 | LRI, left-to-right isolate | Start an LTR span, such as a model ID |
| U+2068 | FSI, first strong isolate | Take direction from the content |
| U+2069 | PDI, pop directional isolate | End any isolate |

UAX #9 encourages isolates over the older embeddings (U+202A to U+202C) in new documents, because embeddings affect surrounding text too strongly, and says overrides (U+202D, U+202E) should be avoided where possible because of security concerns.

## Why it matters

In HTML, W3C advises putting `dir="rtl"` on the `html` element when the page is RTL, and not using CSS to set base direction. For text whose direction you do not know, such as a model reply or a user’s name, use `dir="auto"` or the `bdi` element. W3C notes `auto` decides from the first strong character, so a mostly English paragraph that starts with an Arabic word can still display wrongly.

For API users the usual problems are:

-   **Chat UIs.** A streamed reply starts in English and turns Arabic. Set `dir="auto"` on each message, not once on the page.
-   **JSON and logs.** Model output can contain invisible marks. A value like `"‏gulf"` will not equal `"gulf"`. Strip bidi controls before comparing [structured output](https://broadrouter.com/glossary/structured-output/) fields.
-   **Translated UI strings.** Placeholders and product names inside Arabic need isolates; see [translating app strings to Arabic](https://broadrouter.com/blog/translate-app-strings-to-arabic-llm/).

## On BroadNet Inference

BroadNet’s chat endpoint returns Arabic as ordinary text in the JSON response, as any [OpenAI-compatible API](https://broadrouter.com/glossary/openai-compatible-api/) does, and BroadNet has no display or bidi feature. Direction is your front end’s job. If you also normalize text for search, remove bidi controls in the same pass as [Unicode normalization](https://broadrouter.com/glossary/unicode-normalization/), since NFC and NFKC keep them.

## Common mistakes

-   Reversing Arabic strings in code to “fix” display.
-   Setting direction with CSS only.
-   Leaving U+200F or U+2067 inside IDs, keys or enum values.

## Questions

### Does an LLM API return Arabic text reversed?

No. APIs return characters in logical order, the order they are read. Reversal only happens on display, when the surrounding direction is wrong.

### Should I strip bidi control characters from model output?

Strip overrides (U+202D, U+202E) from untrusted text, since UAX #9 warns they raise security concerns. Isolates and marks are usually harmless, but remove them from values you compare, index or parse.

### Why do my numbers jump to the wrong side of an Arabic sentence?

Digits are weak characters whose position depends on their neighbours. Put the number and its unit in an isolate, or set the paragraph direction explicitly with dir="rtl".

## See also

-   [Unicode normalization](https://broadrouter.com/glossary/unicode-normalization/) (term)
-   [Streaming](https://broadrouter.com/glossary/streaming/) (term)
-   [Structured output](https://broadrouter.com/glossary/structured-output/) (term)
-   [Arabic text normalization](https://broadrouter.com/glossary/arabic-text-normalization/) (term)
-   [JSON Schema](https://broadrouter.com/glossary/json-schema/) (term)
-   [Translate app strings to Arabic with an LLM: placeholders and plurals](https://broadrouter.com/blog/translate-app-strings-to-arabic-llm/) (article)
-   [Arabic–English translation with LLMs: prompts, glossaries, evaluation](https://broadrouter.com/blog/arabic-english-translation-llm/) (article)
-   [Design an AI experience for multiple languages](https://broadrouter.com/blog/multilingual-product-design/) (article)

Try it on your real workload. New accounts start with $5 of credit for Gemma and transcription. DeepSeek, GLM and Qwen3.8 need a top-up.

[Get started](https://inference.broadnet.ai/account/?utm_source=broadrouter&utm_medium=referral&utm_campaign=glossary-rtl-text&utm_content=page-cta) ·

**Sources**

-   [Unicode Standard Annex #9, Unicode Bidirectional Algorithm (Unicode 18.0) (checked 2026-11-15)](https://www.unicode.org/reports/tr9/)
-   [W3C Internationalization, Structural markup and right-to-left text in HTML (checked 2026-11-15)](https://www.w3.org/International/questions/qa-html-dir)
