The Middle East. In perspective.
Business · Culture · Ideas
English edition

Across the region.
Beyond the headlines.

ArabianWeeklyA region in perspectiveAbout the journal
Technology

How Arabic Text Works on Computers: Direction, Joining and Shaping

Arabic is written right to left, its letters change shape depending on neighbours, and numbers and Latin words are mixed in. Here is how Unicode and layout rules make that work on screens.

Tiled niches and calligraphy on a white wall

When a page of Arabic appears on a screen, several systems have to cooperate. The text must run from right to left, each letter must take the right shape for its position in a word, and any English words, numbers or symbols must sit in the right place. Software developers have spent decades building standards to make this work reliably, and the results are largely invisible when they succeed.

What makes Arabic different from Latin text?

Three features stand out.

  1. Direction. Arabic is written from right to left, while Latin text runs from left to right. Pages that combine both, which is common in modern communication, are called bidirectional.
  2. Cursive joining. Arabic letters connect to their neighbours in a word, and most letters have several forms depending on position: isolated, initial, medial and final. The writer does not choose the form; it follows from the letters around it.
  3. Marks and optional vowels. Short vowels and some other sounds are shown by small marks above or below the letters, and in everyday writing they are usually left out. The marks need to be positioned correctly relative to the letters they modify when they are used.

The language itself, and the relationship between its written standard and the spoken dialects, is described in Modern Standard Arabic and the dialects explained.

How does Unicode represent Arabic?

Unicode, the international standard for text, assigns a unique number, called a code point, to each character. For Arabic, it encodes the basic letters in a logical order, the order in which they are read and typed, not the order in which they appear on screen. This design choice means that the stored text is independent of the font and layout: the same sequence of code points can be displayed in different typefaces and sizes.

Importantly, the stored text contains each letter once, without specifying which of its shapes to use. Choosing the right form is the job of the software that displays the text. Unicode also contains older presentation forms of letters for compatibility, but modern software relies on the basic letters and shapes them as needed.

How does the bidirectional algorithm work?

Unicode includes a detailed procedure, defined in a technical report known as UAX #9, the Unicode Bidirectional Algorithm, that determines the display order of text when different directions are mixed. Each character has a bidirectional class. Arabic letters are classed as right-to-left, Latin letters as left-to-right, and punctuation and spaces are neutral, taking their direction from the surrounding text. If the neighbours disagree, neutral characters follow the base direction of the paragraph.

Numbers add complexity. In the algorithm, Arabic-Indic digits are a distinct weak type, and European digits that follow Arabic letters are treated in a way that keeps them readable within right-to-left text. The algorithm is designed so that, for example, a phone number or a price in an Arabic sentence appears in the order a reader expects. The base direction of a paragraph can be set by the author or inferred from the first strong character.

How are letters shaped?

After the display order is determined, the software applies shaping, the process of choosing the correct glyph for each letter. The shaping engine looks at the letter and its neighbours and selects the isolated, initial, medial or final form, and it forms ligatures where required. A well-known example is the combination of lam and alef, which is written as a single connected shape and not as two separate letters.

According to the Unicode report, shaping is applied after the bidirectional algorithm and works within runs of text of the same level. Directional isolates, which separate embedded text, are defined so that characters on either side of them do not join across them. The font plays a major role, because it contains the glyphs and the rules that select among them. A good Arabic font includes many variants and positioning rules, particularly for fonts intended for calligraphic styles, which are a theme in Arabic calligraphy and Islamic geometric art.

What are the layout requirements?

The World Wide Web Consortium maintains a document on Arabic and Persian layout requirements, which describes how text should be laid out on the web, including text direction, the placement of marks, the behaviour of numbers, line breaking and justification. It refers readers to the Unicode report for the formal details of the algorithm and discusses how cursive joining and the algorithm interact. Designers and developers use it as a guide to what users of the script expect.

Some conventions are specific to Arabic, such as the use of an elongation character, called the tatweel or kashida, to stretch words for justification, and the placement of punctuation such as the Arabic question mark and comma. Layout engines have to handle these properly for text to look natural to readers.

What problems do developers still face?

Common difficulties include the following.

  • Mixed direction in user interfaces. When an app interface is mirrored for right-to-left languages, icons, progress bars and menus must also be reversed where appropriate, while some elements, such as media controls and numbers, should not.
  • Search and sorting. Letters with variants and optional marks complicate matching, so search tools often normalise text by ignoring marks or treating certain forms as equivalent.
  • Digits. Arabic-speaking countries use different sets of digits in different places, with both Western and Arabic-Indic forms in use, so software must support the user’s choice.
  • Fonts. Not every font supports all required letters and marks, and fallback fonts can break the look of a page.
  • Dialects. Dialects are largely spoken, and written forms vary, which affects tools such as spelling checkers and voice assistants.

Why does it matter outside the technical community?

The quality of Arabic support determines whether hundreds of millions of people can use websites, apps and devices in their own language without strange behaviour, such as reversed punctuation or disconnected letters. Standards and open-source projects have raised the baseline, but products still vary, and users frequently notice errors. For publishers and businesses in the region, correct handling of Arabic text is a basic part of reaching customers.

It also matters culturally. The script is the vehicle for a literary and artistic tradition, and good digital typography makes it possible to carry some of that tradition into new media. Understanding the language’s place in the wider region, covered in what the Arab world is and how the Arab League works, puts these technical questions in context.

What about keyboards and input?

Typing Arabic requires keyboard layouts that map keys to letters, and in most systems the user can switch between Arabic and Latin layouts with a shortcut. As the user types, the software stores the letters in logical order and shows them right to left, with the cursor moving in the direction of writing. Mobile devices add predictive text and handwriting recognition. Because the visible position of a letter changes as neighbours are added, editing in the middle of a word can be a test of a text engine.

How can people check for problems?

A simple test is to type a mixed sentence with Arabic words, English words and numbers, then look at whether letters connect, punctuation sits correctly and the order of numbers is right. Developers can use the Unicode test suites and the W3C requirements as references. For readers, if text looks wrong on a device, trying a different font or app and reporting the issue can help improve support.

Sources: Unicode Consortium; World Wide Web Consortium