15. XHTML Bi-directional Text Attribute Module


This section is normative.

The Bi-directional Text module defines the Bi-directional attribute collection.

15.1. Bi-directional Text Collection

dir = "ltr|rtl|lro|rlo"
This attribute specifies the base direction of the element's text content. This direction overrides the inherent directionality of characters as defined in Unicode Standard Annex #9: The Bidirectional Algorithm [UAX9], and defines directional properties of text as defined by CSS2 [CSS2]. The default value of this attribute is user-agent dependent, but must be either ltr or rtl. Possible values are:
<p dir="ltr">
The Hebrew word for "Hebrew" is <span xml:lang="he">עברית</span>,
but since Hebrew letters have intrinsic right-to-left directionality,
I had to type the word starting from the letter "ע",
i.e. <span xml:lang="he" dir="lro">עברית</span>.

15.1.3. 15.1.1. Inheritance of text direction information

The Unicode bidirectional algorithm requires a base text direction for text blocks. To specify the base direction of a block-level element, set the element's dir attribute. The default value of the dir attribute is "ltr" (left-to-right text).

When the dir attribute is set for a block-level element, it remains in effect for the duration of the element and any nested block-level elements. Setting the dir attribute on a nested element overrides the inherited value.

To set the base text direction for an entire document, set the dir attribute on the html element.

<html dir="rtl">
<title>...a right-to-left title...</title>
...right-to-left text...
<p dir="ltr">...left-to-right text...</p>
<p>...right-to-left text again...</p>

Inline elements, on the other hand, do not inherit the dir attribute. This means that an inline element without a dir attribute does not open an additional level of embedding with respect to the bidirectional algorithm. (Here, an element is considered to be inline if its default presentation is expressed in [CSS2] as display: inline.)

15.1.4. 15.1.2. The effect of style sheets on bidirectionality

In general, using style sheets to change an element's visual rendering from block-level to inline or vice-versa is straightforward. However, because the bidirectional algorithm relies on the inline/block-level distinction, special care must be taken during the transformation.

When an inline element that does not have a dir attribute is transformed to the style of a block-level element by a style sheet, it inherits the dir attribute from its closest parent block element to define the base direction of the block.

When a block element that does not have a dir attribute is transformed to the style of an inline element by a style sheet, the resulting presentation should be equivalent, in terms of bidirectional formatting, to the formatting obtained by explicitly adding a dir attribute (assigned the inherited value) to the transformed element.

Implementation: RELAX NG