Teaching and Learning with Technology

Computing With Accents and Foreign Scripts

Skip Menu

Right-to-Left (R.T.L.) Text

The technologies for creating right-to-left RTL text have evolved in the past five years. The easiest option is to create or import Unicode text and post it online. The text will be correctly positioned in most cases.

Inherent Direction in Unicode

The Unicode specification includes a directionaly specification for each character depending on its script. Many including Latin A,B,C, etc are encoded as LTR (left to right), but characters from RTL scripts such as Arabic, Hebrew and others are encoded as being RTL.

That means if you activate a Unicode compliant keyboard, then the direction will be automatically changed for characters in an RTL language. The same is true when inserting characters via entity code.

See the following pages for examples and information.

RTL Pages

RTL Words

The easiest way to input right to left text is to use an Arabic or Hebrew keyboard for Windows or Mac and type the text into a text or HTML document. The text will be typed in right to left. If you switch back to English, then text will return to left to right input. By switching keyboards, you can mix languages.

Direction Punctuation

Many punctuation symbols such as the period, parentheses and others are actually "directionless" meaning their positioning may be LTR or RTL depending on what the directionality of adjacent characters are. This can cause unusual effects such as inside out-parentheses unless precautions are taken.

Inside Out Parentheses

(אבג)

vs.

)אבג(

View the Code

<p lang="he">(אבג)</p> vs.
<p lang="he">)אבג(</p>

Typing Tips

  1. Make sure your document is encoded as Unicode.
  2. Experiment with typing interactions. For instance, parentheses may need ot be inserted in the RTL keyboard when adjacent to RTL characters.
  3. Check to be sure Arabic letters are adjoining correctly. Some programs support right-to-left text, but not joining of Arabic letters.

An Example

3 Hebrew letters (אבג) - aleph, beth, gimmel

View the Code

<p>3 Hebrew letters (<b lang="he" class="red">אבג</b>) -<b> aleph, beth, gimmel </b></p>

RTL Paragraphs and Documents

There are several methods to mark a document or passage as dir="rtl" or dir="ltr".

Note that unlike align="right", the punctuation will also relocated. For instance sentence periods appear towards the "begining" or the left edge of a line and bullet points are alinged to the right.

See Sample RTL Document

Right and Left Align a Docment

HTML

Use the code <html dir="rtl" lang=""> to ensure that all paragraphs and headers are right aligned and that the page language is set to either Hebrew (he) or Arabic (ar).

Use the code <html dir="ltr" lang=""> to signify that a page has left-to-right alignment. This could be important if your site is multilingual or a large segment of readers from the Middle East.

XHTML

Use this syntax to declare an "rtl" document and page language. Note that this statement also declares the language as Arabic (ar).

<html xmlns="http://www.w3.org/1999/xhtml" dir="rtl" xml:lang="ar" lang="ar">

Right Aligned Divs and P

The dir="rtl" attribute can be added to DIV's, P's headers and other tags to set alignment for those areas in the text.

Sample HTML - <p lang="ar" dir="rtl">...</p>

Right Alignment with CSS

Use the CSS property direction: rtl for right to left text or direction: ltr for left to right text. Note that this option also places the punctuation to the left of the text.

HTML Code
<div style="direction: rtl" >
<p>Look for me WAAAAAY on the right!!!</p>
</div>

Result

Look for me WAAAAY on the right!!!!

Bidirectional Override (BDO)

If you wish to insert an Arabic or Hebrew word in an English document,  you can use the <bdo dir="rtl"> to temporarily override the left-to-right direction of text as needed.

HTML Code
<p><bdo direction="rtl">hello</bdo></p>

Result

hello

Should see olleh if <bdo> is working.

LTR Override

If you are developing a Hebrew or Arabic Web site, you can use <bdo dir="ltr">English Text Here</bdo> to insert English left-to-right text.

Links

These Web sites provide additional information on developing Right-to-Left Pages.

Top of Page

Wednesday, 19-Dec-2012 16:53:21 EST