Identify Unicode controls for right-to-left text
How to spot the invisible Unicode controls behind right-to-left text, what they change, how they behave when copied, and when plain text or markup is safer.
Right-to-left display in Unicode text comes from two sources. The first is the inherent direction of the characters, such as Arabic or Hebrew letters. The second is a small set of invisible formatting characters that tell the rendering software how to order surrounding text. The second group causes most confusion. These characters take up no visible space, travel with copied text, and can make a string look different from what is actually stored. This review explains how to recognize them, what they really change, and when to use them, replace them with markup, or avoid them.
Short verdict: when right-to-left controls are suitable
Directional controls fit one narrow job: correcting how mixed-direction plain text is displayed when markup is not available. Examples include a Hebrew product name inside an English sentence, or a phone number inside Arabic text. In that role, the isolate characters and the single-character marks are the appropriate tools, because they adjust display order without altering the letters themselves.
The main tradeoff is that the effect depends on the receiving software. Many systems apply the Unicode Bidirectional Algorithm, but some strip the controls, show them as visible symbols, or reject them for security reasons. Using the override character to make ordinary left-to-right text appear reversed is the weakest use. The visible result and the stored text disagree, and that mismatch is the same mechanism used in filename and source-code spoofing.
Plain text with no controls is preferable in several situations. These include text that will be searched, indexed, or matched by software. They also include filenames, usernames, code, and other identifiers, and any content where a reader or reviewer must be able to trust that what they see is what is stored. If the text lives in HTML, direction markup is generally the better choice than embedded control characters.
The directional control characters
The Unicode Standard defines the following characters for controlling bidirectional display. All of them are invisible in normal rendering. The UTF-8 byte sequences are useful when inspecting raw files.
| Code point | Name | Abbreviation | UTF-8 bytes | Kind |
| U+200E | LEFT-TO-RIGHT MARK | LRM | E2 80 8E | Mark |
| U+200F | RIGHT-TO-LEFT MARK | RLM | E2 80 8F | Mark |
| U+061C | ARABIC LETTER MARK | ALM | D8 9C | Mark |
| U+202A | LEFT-TO-RIGHT EMBEDDING | LRE | E2 80 AA | Embedding |
| U+202B | RIGHT-TO-LEFT EMBEDDING | RLE | E2 80 AB | Embedding |
| U+202C | POP DIRECTIONAL FORMATTING | PDF | E2 80 AC | Terminator for embeddings and overrides |
| U+202D | LEFT-TO-RIGHT OVERRIDE | LRO | E2 80 AD | Override |
| U+202E | RIGHT-TO-LEFT OVERRIDE | RLO | E2 80 AE | Override |
| U+2066 | LEFT-TO-RIGHT ISOLATE | LRI | E2 81 A6 | Isolate |
| U+2067 | RIGHT-TO-LEFT ISOLATE | RLI | E2 81 A7 | Isolate |
| U+2068 | FIRST STRONG ISOLATE | FSI | E2 81 A8 | Isolate |
| U+2069 | POP DIRECTIONAL ISOLATE | PDI | E2 81 A9 | Terminator for isolates |
What these controls actually change
Each type of control affects display order in a different way. None of them reorders the other characters in storage.
- Marks (LRM, RLM, ALM) behave like an invisible letter with a strong direction. They influence how nearby neutral characters such as punctuation, spaces, and digits are placed, without starting a new directional region.
- Isolates (LRI, RLI, FSI, closed by PDI) set the direction of the enclosed text and keep it from affecting, or being affected by, the surrounding text. FSI chooses the direction from the first strongly directional character inside it. The bidirectional algorithm's documentation recommends isolates over embeddings for new content.
- Embeddings (LRE, RLE, closed by PDF) set a base direction for the enclosed text but still interact with the surrounding text. This older mechanism tends to produce surprises around punctuation and numbers.
- Overrides (LRO, RLO, closed by PDF) force every enclosed character to be displayed in the stated direction, regardless of its inherent direction. This is the only control that makes ordinary Latin letters appear in reverse order.
The key distinction is between stored order and displayed order. Unicode text is stored in logical order, the order in which it would be read or typed. Directional controls are additional characters inserted into that sequence, and the bidirectional algorithm uses them when it computes how the line is drawn. The letters you see keep their stored positions. Only the drawing order changes.
This matters because the word 'reverse' covers two different operations. A reversal tool that rewrites the string changes the stored characters, and the result stays reversed wherever it is pasted. An override character changes only how the text is displayed. The stored letters remain in the original order, with one extra invisible character in front. 'Mirror' is also ambiguous. Under right-to-left display, paired characters such as parentheses and brackets are mirrored by the algorithm, so an opening parenthesis is drawn as its mirror image. Letters themselves are never drawn as mirror-image glyphs. Tools that claim mirrored letters are substituting different, look-alike characters, which is a separate technique.
An illustration of the override case, written with escape notation so the hidden character is visible:
Stored: \u202E h e l l o
Displayed: olleh (in software that applies the override)
Copied: \u202E h e l l o (the control travels with the text)
Combining marks and multi-code-point emoji behave differently under the two kinds of reversal. Rendering engines that apply the bidirectional algorithm normally keep a base letter and its combining accents together as one visual unit. A naive stored-order reversal tool that flips individual code points can detach an accent from its letter. It can also split an emoji built from several code points, such as a family emoji or a flag, into its components. If you are comparing a display override with a stored reversal, test with accented text and compound emoji, not just plain ASCII.
How to identify hidden directional controls
Because these characters are invisible, you usually notice them through symptoms rather than by seeing them. Common clues include the following.
- Text whose visual order differs from the order in which the cursor moves through it.
- Punctuation that jumps to the wrong end of a line in mixed Arabic or Hebrew and English text.
- A filename whose visible extension does not match the actual file type, such as a name that appears to end in a document extension but opens as a program.
- Source code that appears to say one thing in a viewer while a compiler or interpreter treats it differently.
- A string whose character count or byte length is larger than the visible text suggests.
- Searches or comparisons that fail on text that looks identical.
To confirm, inspect the code points rather than the rendered text. Any method that prints characters as numbers or escape sequences will reveal them. In Python, the following lists each directional control with its position and official name:
import unicodedata
BIDI_CONTROLS = {0x200E, 0x200F, 0x061C,
*range(0x202A, 0x202F),
*range(0x2066, 0x206A)}
def find_bidi_controls(text):
for i, ch in enumerate(text):
if ord(ch) in BIDI_CONTROLS:
print(i, f"U+{ord(ch):04X}", unicodedata.name(ch))
In Python, the built-in ascii() function also prints a string with every non-ASCII character escaped, so an override appears as \u202e. In JavaScript, spreading a string into code points and converting each to hexadecimal gives a similar view:
[...text].map(c => c.codePointAt(0).toString(16).toUpperCase())
For files, a hex dump will show the UTF-8 byte sequences listed in the table above. On systems with GNU grep built with PCRE support and running in a UTF-8 locale, a pattern search can flag lines containing any of these characters. Confirm that your grep supports the -P option before relying on it.
grep -nP '[\x{200E}\x{200F}\x{061C}\x{202A}-\x{202E}\x{2066}-\x{2069}]' file.txt
Some text editors and code review tools can show invisible or control characters or warn about bidirectional characters. Whether yours does, and where the setting lives, varies by product and version, so check its documentation rather than assuming. Useful search terms include 'bidi control characters', 'directional formatting characters', 'Unicode Bidirectional Algorithm', 'UAX #9', 'right-to-left override', 'show invisible characters', and 'Trojan Source', the name given to source-code spoofing that uses these controls.
Copying, sharing, accessibility and search
Directional controls are ordinary characters, so copy and paste normally carries them along. What happens next depends on the destination. Software that implements the bidirectional algorithm displays the intended order. Software that does not may show the text in stored order, draw a placeholder box or symbol, or remove the character. Some platforms filter these characters out of usernames, filenames, or messages because of their misuse. No platform-specific tests were supplied for this review, so a successful rendering in one app should not be taken as evidence for others. Test in the exact destinations you care about.
Screen readers and other assistive technology generally work from the stored text rather than the drawn image. Text that is visually reversed by an override is therefore likely to be read in its original stored order, or announced in a way that does not match what sighted readers see. Conversely, text that has been reversed in storage will be read out backward. Specific screen reader behavior with each control was not tested or documented in the material supplied here. If accessibility matters, verify with the assistive technology your audience uses, and provide a plain-text equivalent for any visually reversed content.
Search and editing are affected in similar ways. A control placed inside a word splits it at the code-point level, so exact-match search, spell checking, and sorting can fail even though the word looks normal. Cursor movement and text selection across mixed-direction runs can feel erratic, because the cursor follows stored order while the eye follows display order. Deleting a control usually requires knowing it is there.
Markup instead of control characters
When text is published as HTML, direction is better expressed in markup. The dir attribute sets base direction, including the value auto for text of unknown direction. The bdi element isolates a run of text from its surroundings, which is the markup counterpart of the isolate characters. The bdo element forces display direction, similar to an override. The CSS properties direction and unicode-bidi provide the same controls at the styling layer. W3C internationalization guidance prefers markup for this purpose, because markup is visible in the source, easier to maintain, and does not alter the stored text that gets copied, searched, or indexed.
Practical recommendations
- For mixed-direction plain text, use isolates (LRI, RLI, FSI with a closing PDI) or a single LRM or RLM. Avoid embeddings in new content.
- Always close embeddings and overrides with PDF, and isolates with PDI. Unclosed controls can affect text that follows.
- Do not use the right-to-left override to make Latin text look reversed if the text needs to be searchable, accessible, or trusted. Use a stored reversal and accept its own limits, or simply leave the text unreversed.
- In HTML, prefer the dir attribute, bdi, and bdo over embedded control characters.
- When receiving text from untrusted sources, especially filenames, identifiers, or code, scan for directional controls before trusting what is displayed.
- Test the result in each actual destination and with any assistive technology your readers rely on. Do not generalize from one rendering.
Evidence gaps
This review relies on the published behavior of the Unicode Bidirectional Algorithm and general, verifiable principles of how Unicode text is stored and processed. No supplied tests cover specific apps, social platforms, browsers, operating systems, or screen readers. Statements about how a particular destination handles these controls should therefore be confirmed by direct testing. No specific tools are recommended here, because none were verified for this review.