Home /Modules/html-spec/dirlang.html

dirlang.html

html-spec/specifications/prose/html-4.01/struct/dirlang.html · 772 line(s) · html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Language information and text direction</title>
<link rel="previous" href="global.html">
<link rel="next" href="text.html">
<link rel="contents" href="../cover.html#toc">
<link rel="stylesheet" type="text/css" href= 
"http://www.w3.org/StyleSheets/TR/W3C-REC">
<link rel="STYLESHEET" href="../style/default.css" type="text/css">
</head>
<body>
<div class="navbar" align="center">&nbsp;<a href="global.html">previous</a>
&nbsp; <a href="text.html">next</a> &nbsp; <a href="../cover.html#minitoc">
contents</a> &nbsp; <a href="../index/elements.html">elements</a> &nbsp; <a
href="../index/attributes.html">attributes</a> &nbsp; <a href= 
"../index/list.html">index</a> 

<hr></div>

<h1 align="center"><a name="h-8">8</a> Language information and text
direction</h1>

<div class="subtoc">
<p><strong>Contents</strong></p>

<ol>
<li><a class="tocxref" href="#h-8.1">Specifying the language of content: the
<samp>lang</samp> attribute</a> 

<ol>
<li><a class="tocxref" href="#h-8.1.1"><span class="index-def" title= 
"language::codes to specify">Language codes</span></a></li>

<li><a class="tocxref" href="#h-8.1.2">Inheritance of language codes</a></li>

<li><a class="tocxref" href="#h-8.1.3">Interpretation of language
codes</a></li>
</ol>
</li>

<li><a class="tocxref" href="#h-8.2">Specifying the direction of text and
tables: the <samp>dir</samp> attribute</a> 

<ol>
<li><a class="tocxref" href="#h-8.2.1">Introduction to the bidirectional
algorithm</a></li>

<li><a class="tocxref" href="#h-8.2.2">Inheritance of text direction
information</a></li>

<li><a class="tocxref" href="#h-8.2.3">Setting the direction of embedded
text</a></li>

<li><a class="tocxref" href="#h-8.2.4">Overriding the bidirectional algorithm:
the <samp class="einst2">BDO</samp> element</a></li>

<li><a class="tocxref" href="#h-8.2.5">Character references for directionality
and joining control</a></li>

<li><a class="tocxref" href="#h-8.2.6">The effect of style sheets on
bidirectionality</a></li>
</ol>
</li>
</ol>
</div>

<p>This section of the document discusses two important issues that affect the
internationalization of HTML: specifying the language (the <a href= 
"dirlang.html#adef-lang" class="noxref"><samp class="ainst">lang</samp></a>
attribute) and direction (the <a href="dirlang.html#adef-dir" class="noxref">
<samp class="ainst">dir</samp></a> attribute) of text in a document.</p>

<h2><a name="h-8.1">8.1</a> <a name="language-info">Specifying the language of
content: the <samp>lang</samp> attribute</a></h2>

<div class="adef-list"><em>Attribute definitions</em> 

<dl>
<dt><a name="adef-lang"><samp class="adef">lang</samp></a> = <a href= 
"../types.html#type-langcode"><em>language-code</em></a> <a href= 
"../types.html#case-insensitive">[CI]</a></dt>

<dd>This attribute specifies the base language of an element's attribute values
and text content. The default value of this attribute is unknown.</dd>
</dl>
</div>

<p><span class="index-inst" title="language::of text"><a name="idx-language-1">
Language information</a></span> specified via the <a href= 
"dirlang.html#adef-lang" class="noxref"><samp class="ainst">lang</samp></a>
attribute may be used by a user agent to control rendering in a variety of
ways. Some situations where author-supplied language information may be helpful
include:</p>

<ul>
<li>Assisting search engines</li>

<li>Assisting speech synthesizers</li>

<li>Helping a user agent select glyph variants for high quality typography</li>

<li>Helping a user agent choose a set of quotation marks</li>

<li>Helping a user agent make decisions about <a href=
"./text.html#hyphenation">hyphenation</a>, ligatures, and spacing</li>

<li>Assisting spell checkers and grammar checkers</li>
</ul>

<p>The <a href="dirlang.html#adef-lang" class="noxref"><samp class="ainst">
lang</samp></a> attribute specifies the language of element content and
attribute values; whether it is <span class="index-inst" title="lang 
attribute::when applicable"><a name="idx-lang_attribute">relevant</a></span>
for a given attribute depends on the syntax and semantics of the attribute and
the operation involved.</p>

<p>The intent of the <a href="dirlang.html#adef-lang" class="noxref"><samp
class="ainst">lang</samp></a> attribute is to allow user agents to render
content more meaningfully based on accepted cultural practice for a given
language. This does not imply that user agents should render characters that
are atypical for a particular language in less meaningful ways; user agents
must make a best attempt to <span class="index-inst" title="characters::best 
effort to render"><a name="idx-characters">render all characters</a></span>,
regardless of the value specified by <a href="dirlang.html#adef-lang" class= 
"noxref"><samp class="ainst">lang</samp></a>.</p>

<div class="example">
<p>For instance, if characters from the Greek alphabet appear in the midst of
English text:</p>

<pre>
&lt;P&gt;&lt;Q lang="en"&gt;Her super-powers were the result of
&amp;gamma;-radiation,&lt;/Q&gt; he explained.&lt;/P&gt;
</pre>

<p>a user agent (1) should try to render the English content in an appropriate
manner (e.g., in its handling the quotation marks) and (2) must make a best
attempt to render &gamma; even though it is not an English character.</p>

<p>Please consult the section on <a href="../charset.html#undisplayable">
undisplayable characters</a> for related information.</p>
</div>

<h3><a name="h-8.1.1">8.1.1</a> <span class="index-def" title="language::codes 
to specify"><a name="langcodes">Language codes</a></span></h3>

<p>The <a href="dirlang.html#adef-lang" class="noxref"><samp class="ainst">
lang</samp></a> attribute's value is a language code that identifies a natural
language spoken, written, or otherwise used for the communication of
information among people. Computer languages are explicitly excluded from
language codes.</p>

<p><a rel="biblioentry" href="../references.html#ref-RFC1766" class="normref">
[RFC1766]</a> defines and explains the language codes that must be used in HTML
documents.</p>

<p>Briefly, language codes consist of a primary code and a possibly empty
series of subcodes:</p>

<pre>
        language-code = primary-code ( "-" subcode )*
</pre>

<div class="example">
<p>Here are some sample language codes:</p>

<ul>
<li>"en": English</li>

<li>"en-US": the U.S. version of English.</li>

<li>"en-cockney": the Cockney version of English.</li>

<li>"i-navajo": the Navajo language spoken by some Native Americans.</li>

<li>"x-klingon": The primary tag "x" indicates an experimental language
tag</li>
</ul>
</div>

<p>Two-letter primary codes are reserved for <a rel="biblioentry" href= 
"../references.html#ref-ISO639" class="normref">[ISO639]</a> language
abbreviations. Two-letter codes include fr (French), de (German), it (Italian),
nl (Dutch), el (Greek), es (Spanish), pt (Portuguese), ar (Arabic), he
(Hebrew), ru (Russian), zh (Chinese), ja (Japanese), hi (Hindi), ur (Urdu), and
sa (Sanskrit).</p>

<p>Any two-letter subcode is understood to be a <a rel="biblioentry" href= 
"../references.html#ref-ISO3166" class="normref">[ISO3166]</a> country
code.</p>

<h3><a name="h-8.1.2">8.1.2</a> Inheritance of language codes</h3>

<p>An element inherits language code information according to the following
order of precedence (highest to lowest):</p>

<ul>
<li>The <a href="dirlang.html#adef-lang" class="noxref"><samp class="ainst">
lang</samp></a> attribute set for the element itself.</li>

<li>The closest parent element that has the <a href="dirlang.html#adef-lang"
class="noxref"><samp class="ainst">lang</samp></a> attribute set (i.e., the <a
href="dirlang.html#adef-lang" class="noxref"><samp class="ainst">
lang</samp></a> attribute is inherited).</li>

<li>The HTTP "Content-Language" header (which may be configured in a server).
For example: 

<pre>
Content-Language: en-cockney
</pre>
</li>

<li>User agent default values and user preferences.</li>
</ul>

<div class="example">
<p>In this example, the primary language of the document is French ("fr"). One
paragraph is declared to be in Spanish ("es"), after which the primary language
returns to French. The following paragraph includes an embedded Japanese ("ja")
phrase, after which the primary language returns to French.</p>

<pre>
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;HTML lang="fr"&gt;
&lt;HEAD&gt;
&lt;TITLE&gt;Un document multilingue&lt;/TITLE&gt;
&lt;/HEAD&gt;
&lt;BODY&gt;
<em>...Interpreted as French...</em>
&lt;P lang="es"&gt;<em>...Interpreted as Spanish...</em>
&lt;P&gt;<em>...Interpreted as French again...</em>
&lt;P&gt;<em>...French text interrupted by</em>&lt;EM lang="ja"&gt;some
         Japanese&lt;/EM&gt;<em>French begins here again...</em>
&lt;/BODY&gt;
&lt;/HTML&gt;
</pre>
</div>

<div class="note"><em><strong>Note.</strong> Table cells may inherit <a href= 
"dirlang.html#adef-lang" class="noxref"><samp class="ainst">lang</samp></a>
values not from its parent but from the first cell in a span. Please consult
the section on <a href="./tables.html#alignment-inheritance">alignment
inheritance</a> for details.</em></div>

<h3><a name="h-8.1.3">8.1.3</a> Interpretation of language codes</h3>

<p>In the context of HTML, a language code should be interpreted by user agents
as a hierarchy of tokens rather than a single token. When a user agent adjusts
rendering according to language information (say, by comparing style sheet
language codes and <a href="dirlang.html#adef-lang" class="noxref"><samp class= 
"ainst">lang</samp></a> values), it should always favor an exact match, but
should also consider matching primary codes to be sufficient. Thus, if the <a
href="dirlang.html#adef-lang" class="noxref"><samp class="ainst">
lang</samp></a> attribute value of "en-US" is set for the <a href= 
"global.html#edef-HTML" class="noxref"><samp class="einst">HTML</samp></a>
element, a user agent should prefer style information that matches "en-US"
first, then the more general value "en".</p>

<div class="note">
<p><em><strong>Note.</strong> Language code hierarchies do not guarantee that
all languages with a common prefix will be understood by those fluent in one or
more of those languages. They do allow a user to request this commonality when
it is true for that user.</em></p>
</div>

<h2><a name="h-8.2">8.2</a> <a name="bidirection">Specifying the direction of
text and tables: the <samp>dir</samp> attribute</a></h2>

<div class="adef-list">
<p><em>Attribute definitions</em></p>

<dl>
<dt><a name="adef-dir"><samp class="adef">dir</samp></a> = <samp>LTR</samp> |
<samp>RTL</samp> <a href="../types.html#case-insensitive">[CI]</a></dt>

<dd>This attribute specifies the base direction of directionally neutral text
(i.e., text that doesn't have inherent directionality as defined in <a rel= 
"biblioentry" href="../references.html#ref-UNICODE" class="normref">
[UNICODE]</a>) in an element's content and attribute values. It also specifies
the <a href="./tables.html#table-directionality">directionality of tables</a>.
Possible values: 

<ul>
<li><samp>LTR</samp>: Left-to-right text or table.</li>

<li><samp>RTL</samp>: Right-to-left text or table.</li>
</ul>
</dd>
</dl>
</div>

<p>In addition to specifying the language of a document with the <a href= 
"dirlang.html#adef-lang" class="noxref"><samp class="ainst">lang</samp></a>
attribute, authors may need to specify the <span class="index-inst" title= 
"text::direction of|direction::of text"><a name="idx-text">base
directionality</a></span> (left-to-right or right-to-left) of portions of a
document's text, of table structure, etc. This is done with the <a href= 
"dirlang.html#adef-dir" class="noxref"><samp class="ainst">dir</samp></a>
attribute.</p>

<p>The <a rel="biblioentry" href="../references.html#ref-UNICODE" class=
"normref">[UNICODE]</a> specification assigns directionality to characters and
defines a (complex) algorithm for determining the proper directionality of
text. If a document does not contain a displayable right-to-left character, a
conforming user agent is not required to apply the <a rel="biblioentry" href= 
"../references.html#ref-UNICODE" class="normref">[UNICODE]</a> bidirectional
algorithm. If a document contains right-to-left characters, and if the user
agent displays these characters, the user agent must use the bidirectional
algorithm.</p>

<p>Although Unicode specifies special characters that deal with text direction,
HTML offers higher-level markup constructs that do the same thing: the <a href= 
"dirlang.html#adef-dir" class="noxref"><samp class="ainst">dir</samp></a>
attribute (do not confuse with the <a href="lists.html#edef-DIR" class=
"noxref"><samp class="einst">DIR</samp></a> element) and the <a href= 
"dirlang.html#edef-BDO" class="noxref"><samp class="einst">BDO</samp></a>
element. Thus, to express a Hebrew quotation, it is more intuitive to write</p>

<pre>
&lt;Q lang="he" dir="rtl"&gt;<em>...a Hebrew quotation...</em>&lt;/Q&gt;
</pre>

<p>than the equivalent with Unicode references:</p>

<pre>
&amp;#x202B;&amp;#x05F4;<em>...a Hebrew quotation...</em>&amp;#x05F4;&amp;#x202C;
</pre>

<p>User agents must <strong>not</strong> use the <span class="index-inst"
title="lang attribute::not for direction"><a name="idx-lang_attribute-1" href= 
"dirlang.html#adef-lang" class="noxref"><samp class="ainst">lang</samp></a>
attribute</span> to determine text directionality.</p>

<p>The <a href="dirlang.html#adef-dir" class="noxref"><samp class="ainst">
dir</samp></a> attribute is inherited and may be overridden. Please consult the
section on the <a href="#blocklevel-bidi">inheritance of text direction
information</a> for details.</p>

<h3><a name="h-8.2.1">8.2.1</a> <span class="index-inst" title= 
"bidirection::Unicode algorithm|Unicode bidirectional algorithm"><a name= 
"idx-bidirection">Introduction to the bidirectional algorithm</a></span></h3>

<p>The following example illustrates the expected behavior of the bidirectional
algorithm. It involves English, a left-to-right script, and Hebrew, a
right-to-left script.</p>

<div class="example">
<p>Consider the following example text:</p>

<pre>
  english1 HEBREW2 english3 HEBREW4 english5 HEBREW6
</pre>

<p>The characters in this example (and in all related examples) are stored in
the computer the way they are displayed here: the first character in the file
is "e", the second is "n", and the last is "6".</p>

<p>Suppose the predominant language of the document containing this paragraph
is English. This means that the base direction is left-to-right. The correct
presentation of this line would be:</p>

<pre>
english1 2WERBEH english3 4WERBEH english5 6WERBEH
         &lt;------          &lt;------          &lt;------
            H                H                H
-------------------------------------------------&gt;
                       E
</pre>

<p>The dotted lines indicate the structure of the sentence: English
predominates and some Hebrew text is embedded. Achieving the correct
presentation requires no additional markup since the Hebrew fragments are
reversed correctly by user agents applying the bidirectional algorithm.</p>

<p>If, on the other hand, the predominant language of the document is Hebrew,
the base direction is right-to-left. The correct presentation is therefore:</p>

<pre>
6WERBEH english5 4WERBEH english3 2WERBEH english1
        -------&gt;         -------&gt;         -------&gt;
            E                E                E
&lt;-------------------------------------------------
                       H
</pre>

<p>In this case, the whole sentence has been presented as right-to-left and the
embedded English sequences have been properly reversed by the bidirectional
algorithm.</p>
</div>

<h3><a name="h-8.2.2">8.2.2</a> <span class="index-inst" title= 
"block-level::and bidirection|direction::inheritance of for nested elements"><a
name="blocklevel-bidi">Inheritance of text direction
information</a></span></h3>

<p>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 <a href="dirlang.html#adef-dir" class="noxref"><samp class="ainst">
dir</samp></a> attribute. The default value of the <a href= 
"dirlang.html#adef-dir" class="noxref"><samp class="ainst">dir</samp></a>
attribute is "ltr" (left-to-right text).</p>

<p>When the <a href="dirlang.html#adef-dir" class="noxref"><samp class="ainst">
dir</samp></a> 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 <a href="dirlang.html#adef-dir" class="noxref"><samp class="ainst">
dir</samp></a> attribute on a nested element overrides the inherited value.</p>

<p>To set the base text direction for an entire document, set the <a href= 
"dirlang.html#adef-dir" class="noxref"><samp class="ainst">dir</samp></a>
attribute on the <a href="global.html#edef-HTML" class="noxref"><samp class= 
"einst">HTML</samp></a> element.</p>

<div class="example">
<p>For example:</p>

<pre>
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;HTML dir="RTL"&gt;
&lt;HEAD&gt;
&lt;TITLE&gt;<em>...a right-to-left title...</em>&lt;/TITLE&gt;
&lt;/HEAD&gt;
<em>...right-to-left text...</em>
&lt;P dir="ltr"&gt;<em>...left-to-right text...</em>&lt;/P&gt;
&lt;P&gt;<em>...right-to-left text again...</em>&lt;/P&gt;
&lt;/HTML&gt;
</pre>
</div>

<p>Inline elements, on the other hand, do not inherit the <a href= 
"dirlang.html#adef-dir" class="noxref"><samp class="ainst">dir</samp></a>
attribute. This means that an inline element without a <a href= 
"dirlang.html#adef-dir" class="noxref"><samp class="ainst">dir</samp></a>
attribute does <strong>not</strong> open an additional level of embedding with
respect to the bidirectional algorithm. (Here, an element is considered to be
block-level or inline based on its default presentation. Note that the <a href= 
"text.html#edef-ins" class="noxref"><samp class="einst">INS</samp></a> and <a
href="text.html#edef-del" class="noxref"><samp class="einst">DEL</samp></a>
elements can be block-level or inline depending on their context.)</p>

<h3><a name="h-8.2.3">8.2.3</a> Setting the direction of embedded text</h3>

<p>The <a rel="biblioentry" href="../references.html#ref-UNICODE" class=
"normref">[UNICODE]</a> bidirectional algorithm automatically reverses embedded
character sequences according to their inherent directionality (as illustrated
by the previous examples). However, in general only one level of embedding can
be accounted for. To achieve additional levels of embedded direction changes,
you must make use of the <a href="dirlang.html#adef-dir" class="noxref"><samp
class="ainst">dir</samp></a> attribute on an inline element.</p>

<div class="example">
<p>Consider the same example text as before:</p>

<pre>
english1 HEBREW2 english3 HEBREW4 english5 HEBREW6
</pre>

<p>Suppose the predominant language of the document containing this paragraph
is English. Furthermore, the above English sentence contains a Hebrew section
extending from HEBREW2 through HEBREW4 and the Hebrew section contains an
English quotation (english3). The desired presentation of the text is thus:</p>

<pre>
english1 4WERBEH english3 2WERBEH english5 6WERBEH
                 -------&gt;
                    E
         &lt;-----------------------
                    H
-------------------------------------------------&gt;
                    E
</pre>

<p>To achieve two embedded direction changes, we must supply additional
information, which we do by delimiting the second embedding explicitly. In this
example, we use the <a href="global.html#edef-SPAN" class="noxref"><samp class= 
"einst">SPAN</samp></a> element and the <a href="dirlang.html#adef-dir" class= 
"noxref"><samp class="ainst">dir</samp></a> attribute to mark up the text:</p>

<pre>
english1 &lt;SPAN dir="RTL"&gt;HEBREW2 english3 HEBREW4&lt;/SPAN&gt; english5 HEBREW6
</pre>
</div>

<p>Authors may also use special Unicode characters to achieve multiple embedded
direction changes. To achieve left-to-right embedding, surround embedded text
with the characters LEFT-TO-RIGHT EMBEDDING ("LRE", hexadecimal 202A) and POP
DIRECTIONAL FORMATTING ("PDF", hexadecimal 202C). To achieve right-to-left
embedding, surround embedded text with the characters RIGHT-TO-LEFT EMBEDDING
("RTE", hexadecimal 202B) and PDF.</p>

<div class="note">
<p><em><strong>Using HTML directionality markup with Unicode
characters.</strong> Authors and designers of authoring software should be
aware that conflicts can arise if the <a href="dirlang.html#adef-dir" class= 
"noxref"><samp class="ainst">dir</samp></a> attribute is used on inline
elements (including <a href="dirlang.html#edef-BDO" class="noxref"><samp class= 
"einst">BDO</samp></a>) concurrently with the corresponding <a rel=
"biblioentry" href="../references.html#ref-UNICODE" class="normref">
[UNICODE]</a> formatting characters. Preferably one or the other should be used
exclusively. The markup method offers a better guarantee of document structural
integrity and alleviates some problems when editing bidirectional HTML text
with a simple text editor, but some software may be more apt at using the <a
rel="biblioentry" href="../references.html#ref-UNICODE" class="normref">
[UNICODE]</a> characters. If both methods are used, great care should be
exercised to insure proper nesting of markup and directional embedding or
override, otherwise, rendering results are undefined.</em></p>
</div>

<h3><a name="h-8.2.4">8.2.4</a> Overriding the bidirectional algorithm: the <a
name="edef-BDO"><samp class="edef">BDO</samp></a> element</h3>

<div class="dtd-fragment">
<pre class="dtd-fragment">
&lt;!ELEMENT <a href="dirlang.html#edef-BDO" class="noxref"><samp class=
"einst">BDO</samp></a> - - (<a href=
"../sgml/dtd.html#inline">%inline;</a>)*          -- I18N BiDi over-ride --&gt;
&lt;!ATTLIST BDO
  <a href=
"../sgml/dtd.html#coreattrs">%coreattrs;</a>                          -- <a
href="global.html#adef-id">id</a>, <a href=
"global.html#adef-class">class</a>, <a href=
"../present/styles.html#adef-style">style</a>, <a href=
"global.html#adef-title">title</a> --
  <a href="dirlang.html#adef-lang" class="noxref"><samp class=
"ainst">lang</samp></a>        <a href=
"../sgml/dtd.html#LanguageCode">%LanguageCode;</a> #IMPLIED  -- language code --
  <a href="dirlang.html#adef-dir-BDO" class="noxref"><samp class=
"ainst-BDO">dir</samp></a>         (ltr|rtl)      #REQUIRED -- directionality --
  &gt;
</pre>
</div>

<p><em>Start tag: <strong>required</strong>, End tag: <strong>
required</strong></em></p>

<div class="adef-list">
<p><em>Attribute definitions</em></p>

<dl>
<dt><a name="adef-dir-BDO"><samp class="adef">dir</samp></a> = <samp>LTR</samp>
| <samp>RTL</samp> <a href="../types.html#case-insensitive">[CI]</a></dt>

<dd>This mandatory attribute specifies the base direction of the element's text
content. This direction overrides the inherent directionality of characters as
defined in <a rel="biblioentry" href="../references.html#ref-UNICODE" class= 
"normref">[UNICODE]</a>. Possible values: 

<ul>
<li><samp>LTR</samp>: Left-to-right text.</li>

<li><samp>RTL</samp>: Right-to-left text.</li>
</ul>
</dd>
</dl>
</div>

<div class="aref-list">
<p><em>Attributes defined elsewhere</em></p>

<ul>
<li><a href="dirlang.html#adef-lang" class="noxref"><samp class="ainst">
lang</samp></a> (<a href="#language-info">language information</a>)</li>
</ul>
</div>

<p>The bidirectional algorithm and the <a href="dirlang.html#adef-dir" class= 
"noxref"><samp class="ainst">dir</samp></a> attribute generally suffice to
manage embedded direction changes. However, some situations may arise when the
bidirectional algorithm results in incorrect presentation. The <a href= 
"dirlang.html#edef-BDO" class="noxref"><samp class="einst">BDO</samp></a>
element allows authors to <span class="index-inst" title="bidirection::override 
of"><a name="idx-bidirection-1">turn off</a></span> the bidirectional algorithm
for selected fragments of text.</p>

<div class="example">
<p>Consider a document containing the same text as before:</p>

<pre>
english1 HEBREW2 english3 HEBREW4 english5 HEBREW6
</pre>

<p>but assume that this text has already been put in visual order. One reason
for this may be that the MIME standard (<a rel="biblioentry" href= 
"../references.html#ref-RFC2045" class="normref">[RFC2045]</a>, <a rel= 
"biblioentry" href="../references.html#ref-RFC1556" class="normref">
[RFC1556]</a>) favors visual order, i.e., that right-to-left character
sequences are inserted right-to-left in the byte stream. In an email, the above
might be formatted, including line breaks, as:</p>

<pre>
english1 2WERBEH english3
4WERBEH english5 6WERBEH
</pre>

<p>This conflicts with the <a rel="biblioentry" href= 
"../references.html#ref-UNICODE" class="normref">[UNICODE]</a> bidirectional
algorithm, because that algorithm would invert <tt>2WERBEH</tt>, <tt>
4WERBEH</tt>, and <tt>6WERBEH</tt> a second time, displaying the Hebrew words
left-to-right instead of right-to-left.</p>

<p>The solution in this case is to override the bidirectional algorithm by
putting the Email excerpt in a <a href="text.html#edef-PRE" class="noxref">
<samp class="einst">PRE</samp></a> element (to conserve line breaks) and each
line in a <a href="dirlang.html#edef-BDO" class="noxref"><samp class="einst">
BDO</samp></a> element, whose <a href="dirlang.html#adef-dir-BDO" class=
"noxref"><samp class="ainst-BDO">dir</samp></a> attribute is set to <samp>
LTR</samp>:</p>

<pre>
&lt;PRE&gt;
&lt;BDO dir="LTR"&gt;english1 2WERBEH english3&lt;/BDO&gt;
&lt;BDO dir="LTR"&gt;4WERBEH english5 6WERBEH&lt;/BDO&gt;
&lt;/PRE&gt;
</pre>

<p>This tells the bidirectional algorithm "Leave me left-to-right!" and would
produce the desired presentation:</p>

<pre>
english1 2WERBEH english3
4WERBEH english5 6WERBEH
</pre>
</div>

<p>The <a href="dirlang.html#edef-BDO" class="noxref"><samp class="einst">
BDO</samp></a> element should be used in scenarios where absolute control over
sequence order is required (e.g., multi-language part numbers). The <a href= 
"dirlang.html#adef-dir-BDO" class="noxref"><samp class="ainst-BDO">
dir</samp></a> attribute is mandatory for this element.</p>

<p>Authors may also use special Unicode characters to override the
bidirectional algorithm -- LEFT-TO-RIGHT OVERRIDE (202D) or RIGHT-TO-LEFT
OVERRIDE (hexadecimal 202E). The POP DIRECTIONAL FORMATTING (hexadecimal 202C)
character ends either bidirectional override.</p>

<div class="note">
<p><em><strong>Note.</strong> Recall that conflicts can arise if the <a href= 
"dirlang.html#adef-dir" class="noxref"><samp class="ainst">dir</samp></a>
attribute is used on inline elements (including <a href="dirlang.html#edef-BDO"
class="noxref"><samp class="einst">BDO</samp></a>) concurrently with the
corresponding <a rel="biblioentry" href="../references.html#ref-UNICODE" class= 
"normref">[UNICODE]</a> formatting characters.</em></p>
</div>

<div class="note">
<p><em><span class="index-inst" title="bidirection::and character 
encoding|character encoding::and bidirection"><strong><a name="bidi88598">
Bidirectionality and character encoding</a></strong></span> According to <a
rel="biblioentry" href="../references.html#ref-RFC1555" class="normref">
[RFC1555]</a> and <a rel="biblioentry" href="../references.html#ref-RFC1556"
class="normref">[RFC1556]</a>, there are special conventions for the use of
"charset" parameter values to indicate bidirectional treatment in MIME mail, in
particular to distinguish between visual, implicit, and explicit
directionality. The parameter value "ISO-8859-8" (for Hebrew) denotes visual
encoding, "ISO-8859-8-i" denotes implicit bidirectionality, and "ISO-8859-8-e"
denotes explicit directionality.</em></p>

<p><em>Because HTML uses the Unicode bidirectionality algorithm, conforming
documents encoded using ISO 8859-8 must be labeled as "ISO-8859-8-i". Explicit
directional control is also possible with HTML, but cannot be expressed with
ISO 8859-8, so "ISO-8859-8-e" should not be used.</em></p>

<p><em>The value "ISO-8859-8" implies that the document is formatted visually,
misusing some markup (such as <a href="tables.html#edef-TABLE" class="noxref">
<samp class="einst">TABLE</samp></a> with right alignment and no line wrapping)
to ensure reasonable display on older user agents that do not handle
bidirectionality. Such documents do not conform to the present specification.
If necessary, they can be made to conform to the current specification (and at
the same time will be displayed correctly on older user agents) by adding <a
href="dirlang.html#edef-BDO" class="noxref"><samp class="einst">BDO</samp></a>
markup where necessary.</em> <em>Contrary to what is said in <a rel=
"biblioentry" href="../references.html#ref-RFC1555" class="normref">
[RFC1555]</a> and <a rel="biblioentry" href="../references.html#ref-RFC1556"
class="normref">[RFC1556]</a>, ISO-8859-6 (Arabic) is <strong>not</strong>
visual ordering.</em></p>
</div>

<h3><a name="h-8.2.5">8.2.5</a> <span class="index-inst" title="character 
reference::for directionality"><a name="idx-character_reference">Character
references for directionality and joining control</a></span></h3>

<p>Since ambiguities sometimes arise as to the directionality of certain
characters (e.g., punctuation), the <a rel="biblioentry" href= 
"../references.html#ref-UNICODE" class="normref">[UNICODE]</a> specification
includes characters to enable their proper resolution. Also, Unicode includes
some characters to control joining behavior where this is necessary (e.g., some
situations with Arabic letters). HTML 4 includes <a href=
"../sgml/entities.html">character references</a> for these characters.</p>

<p>The following DTD excerpt presents some of the directional entities:</p>

<pre>
   &lt;!ENTITY zwnj CDATA "&amp;#8204;"--=zero width non-joiner--&gt;
   &lt;!ENTITY zwj  CDATA "&amp;#8205;"--=zero width joiner--&gt;
   &lt;!ENTITY lrm  CDATA "&amp;#8206;"--=left-to-right mark--&gt;
   &lt;!ENTITY rlm  CDATA "&amp;#8207;"--=right-to-left mark--&gt;
</pre>

<p>The <samp>zwnj</samp> entity is used to block joining behavior in contexts
where joining will occur but shouldn't. The <samp>zwj</samp> entity does the
opposite; it forces joining when it wouldn't occur but should. For example, the
Arabic letter "HEH" is used to abbreviate "Hijri", the name of the Islamic
calendar system. Since the isolated form of "HEH" looks like the digit five as
employed in Arabic script (based on Indic digits), in order to prevent
confusing "HEH" as a final digit five in a year, the initial form of "HEH" is
used. However, there is no following context (i.e., a joining letter) to which
the "HEH" can join. The <samp>zwj</samp> character provides that context.</p>

<p>Similarly, in Persian texts, there are cases where a letter that normally
would join a subsequent letter in a cursive connection should not. The
character <samp>zwnj</samp> is used to block joining in such cases.</p>

<p>The other characters, <samp>lrm</samp> and <samp>rlm</samp>, are used to
force directionality of directionally neutral characters. For example, if a
double quotation mark comes between an Arabic (right-to-left) and a Latin
(left-to-right) letter, the direction of the quotation mark is not clear (is it
quoting the Arabic text or the Latin text?). The <samp>lrm</samp> and <samp>
rlm</samp> characters have a directional property but no width and no word/line
break property. Please consult <a rel="biblioentry" href= 
"../references.html#ref-UNICODE" class="normref">[UNICODE]</a> for more
details.</p>

<div class="note">
<p><em><strong>Mirrored character glyphs.</strong> In general, the
bidirectional algorithm does not mirror character glyphs but leaves them
unaffected. An exception are characters such as parentheses (see <a rel= 
"biblioentry" href="../references.html#ref-UNICODE" class="normref">
[UNICODE]</a>, table 4-7). In cases where mirroring is desired, for example for
Egyptian Hieroglyphs, Greek Bustrophedon, or special design effects, this
should be controlled with styles.</em></p>
</div>

<h3><a name="h-8.2.6">8.2.6</a> <span class="index-inst" title="style 
sheet::and bidirection|bidirection::and style sheets"><a name="style-bidi">The
effect of style sheets on bidirectionality</a></span></h3>

<p>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 <a href="#blocklevel-bidi">
inline/block-level distinction</a>, special care must be taken during the
transformation.</p>

<p>When an inline element that does not have a <a href="dirlang.html#adef-dir"
class="noxref"><samp class="ainst">dir</samp></a> attribute is transformed to
the style of a block-level element by a style sheet, it inherits the <a href= 
"dirlang.html#adef-dir" class="noxref"><samp class="ainst">dir</samp></a>
attribute from its closest parent block element to define the base direction of
the block.</p>

<p>When a block element that does not have a <a href="dirlang.html#adef-dir"
class="noxref"><samp class="ainst">dir</samp></a> 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 <a href="dirlang.html#adef-dir" class="noxref">
<samp class="ainst">dir</samp></a> attribute (assigned the inherited value) to
the transformed element.</p>

<div class="navbar" align="center">
<hr><a href="global.html">previous</a> &nbsp; <a href="text.html">next</a>
&nbsp; <a href="../cover.html#minitoc">contents</a> &nbsp; <a href= 
"../index/elements.html">elements</a> &nbsp; <a href=
"../index/attributes.html">attributes</a> &nbsp; <a href="../index/list.html">
index</a></div>
</body>
</html>