Skip to Content (Press Enter)

This document is a draft, and is designed to show changes from a previous version. It is presently showing added text,changed text,deleted text,[start]/[end] markers,and Issue Numbers.

Hide All Edits   |   Toggle Deletions  |   Toggle Issue Numbers   |   Toggle [start]/[end] Markers   |   Show All Edits

Changes are displayed as follows:

H56: Using the dir attribute on an inline element to resolve problems with nested directional runs


HTML 4, XHTML 1.0 and XHTML 1.1

This technique relates to:

User Agent and Assistive Technology Support Notes


The objective of this technique is to identify changes in the text direction of text that includes nested directional runs by providing the dir attribute on inline elements. A nested directional run is a run of text that includes mixed directional text, for example, a paragraph in English containing a quoted Hebrew sentence which in turn includes a quotation in French. Use of the dir attribute on an enclosing span or other inline element may be necessary because the Unicode bidirectional algorithm can produce undesirable results when mixed directional text contains spaces or punctuation. [begin add]The concepts used in this technique are described in What you need to know about the bidi algorithm and inline markup. [1966] [end add]


Example 1

This example defines the text direction of a mixed phrase, Hebrew and English, to be right-to-left. Because the whole quote is in Hebrew, and therefore runs right to left, the text "W3C" and the comma should appear to the left of (i.e. after) the Hebrew text.

<p>The title says "<span lang="he" dir="rtl">פעילות הבינאום, <span lang="en" dir="ltr">W3C</span></span>" in Hebrew.</p>

This produces the result:

The title says "פעילות הבינאום, W3C " in Hebrew.


Resources are for information purposes only, no endorsement implied.



  1. Examine the text direction of text in the document

  2. If the text direction is right-to-left, check that for the ancestor element that has a dir attribute, the attribute has the value "rtl"

  3. If the text direction is left-to-right, check that there is no ancestor element with a dir attribute, or that for the ancestor element that has a dir attribute, the attribute has the value "ltr"

Expected Results