Bidirectional text rendering is the algorithmic process defined by the Unicode Bidirectional Algorithm (UBA) that resolves the display order of characters with mixed directionality. When a sentence embeds an English quote inside an Arabic paragraph, the rendering engine must logically determine the visual placement of punctuation, numbers, and neutral characters based on their surrounding directional context, not their storage order in memory.
Glossary
Bidirectional Text Rendering

What is Bidirectional Text Rendering?
Bidirectional text rendering is the software capability to correctly display and format text that mixes left-to-right (LTR) scripts, like English, with right-to-left (RTL) scripts, like Arabic or Hebrew, within the same paragraph or user interface element.
This capability is a core requirement of internationalization (i18n) and relies on libraries like ICU4C and HarfBuzz to handle complex script shaping. Failure to implement correct bidirectional rendering results in garbled text, misplaced punctuation, and broken user interfaces, making the application unusable for RTL markets.
Core Characteristics of BiDi Rendering
Bidirectional text rendering is a complex software engineering discipline that ensures the correct visual display and logical ordering of mixed-script text. It relies on the Unicode Bidirectional Algorithm to resolve the inherent conflict between left-to-right and right-to-left character directionality.
The Unicode Bidirectional Algorithm (UBA)
The foundational specification that defines how text containing both left-to-right (LTR) and right-to-left (RTL) scripts is ordered for display. The UBA assigns a directional type to every character and uses a set of explicit rules to resolve ambiguities.
- Implicit Ordering: Characters are assigned levels (0 for LTR, 1 for RTL) based on their inherent direction.
- Explicit Overrides: Control characters like LRE (Left-to-Right Embedding) and RLE (Right-to-Left Embedding) force a specific direction.
- Mirroring: Characters like parentheses
()are automatically mirrored to)(when rendered in an RTL context to maintain logical syntax.
Logical vs. Visual Ordering
A critical distinction in BiDi rendering is the separation of storage order from display order. Text is always stored in logical order—the sequence in which characters are typed and processed by the system.
- Logical Order: The underlying string in memory, e.g.,
Hello שלום. - Visual Order: The rendered output on screen, where the RTL segment is displayed right-to-left.
- Caret Navigation: A key challenge is ensuring the text cursor moves in the logical order, not the visual order, to prevent disjointed editing experiences.
Directional Isolates and Embedding
Modern BiDi rendering uses directional isolates to cleanly separate text segments with different base directions, preventing the spill-over effect that plagued older embedding methods.
- RLI/LRI/FSI: Right-to-Left Isolate, Left-to-Right Isolate, and First-Strong Isolate characters create a new directional context that is completely independent of the surrounding text.
- LRE/RLE (Legacy): Older embedding characters that could cause the direction of one segment to influence adjacent punctuation, leading to the 'leaky' BiDi bug.
- PDF (Pop Directional Format): A control character that terminates the effect of the last explicit embedding or override.
Handling Neutral Characters
Characters like spaces, punctuation, and numbers are directionally neutral. Their rendering direction is determined by the surrounding strongly-typed characters, making them a primary source of rendering bugs.
- Weak Characters: Numbers and currency symbols have a weak directionality and can be influenced by adjacent text.
- Neutral Characters: Spaces and most punctuation adopt the direction of the surrounding paragraph or embedding level.
- Common Bug: A period at the end of a mixed-script sentence may render on the wrong side of the text if the surrounding directional context is not correctly resolved.
Paragraph-Level Direction
The base direction of a block of text is set at the paragraph level, providing the foundational context for the entire BiDi algorithm. This can be set explicitly or detected heuristically.
- First-Strong Heuristic: The algorithm scans for the first character with a strong direction (e.g., an Arabic or Latin letter) and sets the paragraph's base direction accordingly.
- Explicit Declaration: In HTML, the
dirattribute (dir='rtl') or the CSSdirectionproperty overrides the heuristic and sets the base direction definitively. - Alignment: The base direction also controls the default text alignment—right-aligned for RTL paragraphs, left-aligned for LTR.
Mirroring and Glyph Substitution
Beyond character ordering, BiDi rendering requires glyph mirroring to ensure that the visual representation of a character matches its logical function in an RTL context.
- Paired Punctuation: Characters like
(,[,{, and«are replaced with their mirrored counterparts),],}, and»when resolved to an RTL level. - Glyph Shaping: For cursive scripts like Arabic, characters must also undergo contextual shaping, where a letter's form changes based on its position (isolated, initial, medial, final) within a word.
- Combined Process: Mirroring and shaping happen after the BiDi levels are resolved, as part of the final layout and rendering pipeline.
Frequently Asked Questions
Clear, technical answers to the most common questions about implementing and debugging bidirectional text rendering in modern software applications.
Bidirectional (bidi) text rendering is the process by which a software application correctly displays and formats text that mixes both left-to-right (LTR) scripts, such as English or Latin, and right-to-left (RTL) scripts, such as Arabic, Hebrew, or Persian, within the same paragraph. The core mechanism relies on the Unicode Bidirectional Algorithm (UBA) , defined in Unicode Standard Annex #9. The UBA assigns a directional type to every character—strong LTR, strong RTL, or neutral—and then resolves the embedding levels of each character based on an implicit set of rules. This determines the visual ordering of characters on the screen, which often differs from their logical storage order in memory. For example, in a sentence mixing English and Arabic, the logical first character might not be the visual first character. The algorithm handles nested embeddings, directional overrides, and the mirroring of glyphs like parentheses to ensure the text is human-readable.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Explore the core concepts, algorithms, and standards that enable software to correctly display and format text mixing left-to-right and right-to-left scripts within the same paragraph.
Unicode Bidirectional Algorithm (UBA)
The foundational standard defined by the Unicode Consortium for determining the display order of text with mixed directionality. The UBA uses a set of rules to assign an implicit direction to each character based on its properties, then resolves the visual order. Key concepts include:
- Directional Types: Characters are classified as L (left-to-right), R (right-to-left), AL (Arabic letter), or AN (Arabic number).
- Embedding Levels: A stack-based mechanism that tracks nested directional contexts, allowing a Hebrew quote inside an English paragraph to render correctly.
- Mirroring: Characters like parentheses
()are automatically mirrored to)(when rendered in an RTL context to maintain logical grouping.
Logical vs. Visual Order
A critical distinction in bidirectional text processing. Logical order is the sequence in which characters are stored in memory and typed on a keyboard, corresponding to the phonetic order of the text. Visual order is the sequence in which glyphs are displayed on the screen. For a mixed string like 'English עברית text', the logical order is E-n-g-l-i-s-h-[space]-ע-ב-ר-י-ת-[space]-t-e-x-t, but the visual order must display 'English' left-to-right, then 'תירבע' right-to-left, then 'text' left-to-right. The UBA is the engine that performs this transformation.
Directional Formatting Characters
Invisible Unicode characters used to override or control the bidirectional behavior of text when the implicit algorithm is insufficient. These are essential for edge cases in data entry and display:
- RLM (Right-to-Left Mark, U+200F): An invisible, strong RTL character that forces the resolution of a neutrally-directional character (like a punctuation mark) to be treated as part of an RTL run.
- LRM (Left-to-Right Mark, U+200E): The LTR equivalent of the RLM.
- LRE/RLE (Embedding, U+202A/U+202B): Start a new directional embedding level, treating the enclosed text as a solid LTR or RTL block.
- PDF (Pop Directional Formatting, U+202C): Terminates the most recent LRE or RLE embedding.
CSS `direction` and `unicode-bidi` Properties
The primary web platform mechanisms for controlling bidirectional text rendering. The direction property sets the base direction of a block-level element (ltr or rtl), which determines the alignment of text and the order of table columns. The unicode-bidi property controls how the Unicode Bidirectional Algorithm interacts with the document's markup:
normal: The default; the UBA handles all bidirectional resolution.embed: Creates an additional embedding level, useful for isolating an inline RTL span within LTR text.bidi-override: Forces a strict visual reordering, ignoring the implicit UBA rules—essential for displaying a reversed string for testing.isolate: Renders the element as a directional island, preventing its content from influencing the ordering of surrounding text.
Glyph Shaping and Contextual Joining
Beyond simple reordering, bidirectional rendering for scripts like Arabic requires complex glyph shaping. Arabic is a cursive script where the visual form of a letter changes depending on its position in a word (isolated, initial, medial, or final). The rendering engine must analyze the logical character string, determine the correct contextual form for each letter, and then apply the bidirectional reordering. This process is handled by the OS's text layout engine, such as DirectWrite on Windows or Core Text on macOS, using OpenType font tables like the Glyph Substitution Table (GSUB).
Neutral Character Resolution
A key step in the UBA where characters without an inherent direction—such as spaces, punctuation, and symbols—are assigned a direction based on their surrounding context. A period at the end of an English sentence is LTR, but a period at the end of a Hebrew sentence must become RTL to position correctly. The algorithm resolves these weak types by examining the strong directional characters on either side, ensuring that punctuation and whitespace flow with the text they belong to, preventing broken visual fragments.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us