W3C

Authoring Techniques for XHTML & HTML Internationalization 1.0

W3C Working Draft 9 October 2003

This version:
http://www.w3.org/TR/2003/WD-i18n-html-tech-20031009/
Latest version:
http://www.w3.org/TR/i18n-html-tech/
Editor:
Richard Ishida, W3C <ishida@w3.org>

Abstract

This document provides HTML authors with techniques for developing internationalized HTML using XHTML 1.0 or HTML 4.01, supported by CSS1, CSS2 and some aspects of CSS3. It is produced by the Guidelines, Education & Outreach Task Force (GEO) of the W3C Internationalization Working Group (I18N WG). The GEO Task Force encourages feedback about the content of this document as well as participation in the development of the techniques by people who have experience creating Web content that conforms to internationalization needs.

Status of this Document

This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.

This is the first Working Draft of a document produced by the GEO (Guidelines, Education & Outreach) Task Force of the W3C Internationalization Working Group (I18N WG). This is a draft document that does not fully represent the consensus of the group at this time. Some sections have been fleshed out but need some more work, other sections are still missing. (Titles of empty sections are preceded by an asterisk in the Table of Contents.)

The document provides practical techniques that HTML content authors can use to ensure that their HTML is easily adaptable for an international audience. These are techniques that need to be addressed from the start of content development if unnecessary costs and resource issues are to be avoided later on. They are aimed at the developer as well as the localizer.

The Task Force encourages feedback about the content of this document as well as participation in the development of the guidelines by people who have experience creating Web content that conforms to internationalization needs. Send comments about this document to www-i18n-comments@w3.org. The archives for this list are publicly available.

This document is published as part of the W3C Internationalization Activity by the Internationalization Working Group, with the help of the Internationalization Interest Group. The Internationalization Working Group will not allow early implementation to constrain its ability to make changes to this specification prior to final release. Publication as a Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.

At the time of publication, the Working Group believed there were no patent disclosures relevant to this specification. A current list of patent disclosures relevant to this specification may be found on the Working Group's patent disclosure page.

Table of Contents

1 Introduction
    1.1 Who should use this document
    1.2 How to use this document
    1.3 Standards addressed
    1.4 User agents addressed
2 Document structure & metadata
    2.1 Internationalizing the page header
    2.2 International layout considerations
    2.3 * Document structure
    2.4 * Sentence fragmentation & reuse
    2.5 * Ordering text
    2.6 * Separating semantics from presentation
3 Character sets, character encodings and entities
    3.1 Choosing a page encoding
    3.2 Specifying a page encoding
    3.3 Referring to specific characters
    3.4 * Specifying the encoding of a link destination
4 Fonts
    4.1 Choosing & specifying fonts
    4.2 Dealing with undisplayable characters
    4.3 * Installing multilingual fonts
    4.4 * Pages containing multiple languages
5 Specifying the language of content
    5.1 Specifying the overall language of a document
    5.2 Identifying language change
    5.3 Specifying the language of a link destination
    5.4 Specifying language codes
6 Handling bidirectional text
    6.1 Enabling easy localization for RTL scripts
    6.2 General use of bidi markup
    6.3 Basic setup for pages in RTL scripts
    6.4 Changing the directionality of a block element
    6.5 Mixing text direction inline
    6.6 Handling parentheses & other mirrored characters
    6.7 Overriding the Unicode bidirectional algorithm
    6.8 * Enabling mirroring of layout
7 * Handling vertical text
8 * Text formatting
    8.1 * Emphasis
    8.2 * Acronyms & abbreviations
    8.3 * Quotations
    8.4 * Ruby
    8.5 * Use of pre text
    8.6 * Applying visual style conventions
9 * Lists
    9.1 * Implementing language-specific list markers
10 * Tables
    10.1 * Mirroring tables in bidirectional text
    10.2 * Specifying table dimensions
    10.3 * Alignment issues
    10.4 * (Other issues)
11 * Links
    11.1 * Keyboard access to links
    11.2 * Using non-ASCII characters in link targets
    11.3 * Including encoding & language information in links
    11.4 * Linking in a multilingual site
12 * Objects
    12.1 * Determining the runtime locale for an object
    12.2 * Dealing with embedded objects with different encodings
13 * Images
    13.1 * Creating culturally appropriate graphics
    13.2 * Using text in graphics
    13.3 * Using image maps
    13.4 * Using color
    13.5 * Dealing with directional bias in graphics
    13.6 * Creating localizable graphics
14 Handling data that varies by locale
    14.1 Date & time
    14.2 * Numbers
    14.3 * Currency
    14.4 * (Other stuff: measurements, addresses, telephone numbers, personal names, paper sizes...)
15 Forms
    15.1 * Dealing with character sets & encodings
    15.2 * Keyboard access to forms
    15.3 * Creating culturally appropriate forms
    15.4 * Creating buttons
16 * Keyboard shortcuts
17 * Writing source text
    17.1 * Writing clear, understandable text
    17.2 * Using metaphors, examples and humour
    17.3 * Using abbreviations & acronyms
18 * Navigation
    18.1 * Navigating to the preferred localized web site
    18.2 * Implementing international contact pages
19 * File management
20 * Supplying data for localization

Appendices

A Acknowledgements
B References


1 Introduction

Go to outline view...Return to top of contents...1.1 Who should use this document

All HTML content authors working with XHTML 1.0, HTML 4.01, CSS1, CSS2 and CSS3.

The term author is used in the sense described by the HTML 4.01 spec, ie. as a person or program that writes or generates HTML documents.

This document provides guidance for the development of HTML so that it will support international usage. This is the responsibility of all content authors, not just the localization group, and is relevant from the very start of development. Ignoring the advice in this document, or relegating it to a later phase in the development, will only add unnecessary costs and resource issues at a later date.

Go to outline view...Return to top of contents...1.2 How to use this document

To improve usability, the table of contents of this document represents tasks that a developer of XHMTL/HTML content may want to perform.

It is expected that this document will normally be used for reference purposes - the reader dipping in to a particular section to find out how to perform a specific task with internationalization in mind. If you are new to this topic you may, however, wish to read this document from end to end.

To further assist usability as a reference, an outline version of the document is available. There is also a version that contains only resource links. The reader can switch between outline, resource, and detailed versions by clicking on icons alongside section headings.

Note that, to support its use as a quick reference, the same material will occasionally be repeated in more than one section.

Cross references and further resources are summarized at the end of each section.

Editorial notes have been left in this version of the document. These are marked .

It is assumed that readers of this document are proficient in developing HTML and XHTML pages - this document limits itself to providing internationalization advice.

Go to outline view...Return to top of contents...1.3 Standards addressed

This document provides techniques for developing pages using HTML 4.01 or XHTML 1.0 with CSS1, CSS2 and CSS3.

Note that XHTML source can be served as XML (using MIME types application/xhtml+xml, application/xml or text/xml) or HTML (using the MIME type text/html).

It is very common for XHTML to be served as HTML, following the compatibility guidelines in Appendix C of the XHTML 1.0 specification. This allows authors with the right editing tools to produce valid XML code, which therefore lends itself to processing with such things as scripting or XSLT, but is also well supported for display by most mainstream browsers. (XHTML served as application/xhtml+xml is not well supported for browser display at the moment.) In this document we wish to reflect practical reality for content authors, so we cover XHTML served as text/html in the techniques.

Indeed we encourage the use of XHTML, and all the examples (unless trying to make a specific point about HTML 4.01) are written in XHTML.

For XHTML served as XML, this document limits its advice to documents served as application/xhtml+xml. Note that user agent support for XHTML served as XML is still patchy.

Go to outline view...Return to top of contents...1.4 User agents addressed

In order to improve the value of this information to the user we try to ground techniques with information about their applicability to particular user agents.

User agents, in this current version, means a number of mainstream browsers. (The scope may grow as resources and test results become available for other user agents.)

In an attempt to make the task of tracking browser applicability manageable, we have chosen a 'base version' for each of the user agents we are tracking for applicability. This base version represents a fairly recent, standards-compliant version of the browser. Where a browser operates in both standards- and quirks-mode, standards-mode is assumed (ie. you should use a DOCTYPE statement).

The base versions considered for this version of the document include:

  • Internet Explorer 6 (Windows)

  • Netscape Navigator 7

  • Opera 7

If the technique is applicable to a base version of a user agent the name of that user agent will appear immediately below the summary of the technique. If the technique is not applicable, the name will appear crossed out. If the name does not appear at all, this signifies that further investigation is needed. If the technique is applicable to a later version than the chosen base version, this will be indicated by adding the version number to the name.

Plans exist to provide information relating to the following additional user agents as work on the document progresses:

  • Internet Explorer 5 (Mac)

  • Safari

  • Mozilla

Detailed information may also be provided from time to time about behavior of a user agent in an earlier version than the base version, or about some particular aspect of the behavior of a base version or later user agent. This is provided in a special boxed section within the body of the text.

2 Document structure & metadata

Go to outline view...Return to top of contents...2.1 Internationalizing the page header

Creating an internationalized page header principally consists of declaring the encoding and language of the document.

For HTML documents and XHTML documents served as text/html, always use the meta element to explicitly declare the document's character encoding.

 IE(Win)  NNav  Opera 

To do this, assign an IANA charset name as the charset value of a meta http-equiv statement.

Example:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xml:lang="en" lang="en">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

<title>Sample document</title>

...

This is good practise even if the character encoding has already been specified in the HTTP Content-Type parameter or any XML declaration (in XHTML). It ensures that the character encoding is always declared even if the document is at some point not read from that server (eg. a local copy is read from disk, or the file is moved to another server that is not set up to serve the Content-Type parameter).

Note that the XHTML specification recommends that the character encoding be declared in both the meta charset declaration and the XML declaration.

Note also that you should include a character encoding declaration even if your document uses a basic Latin encoding such as ISO 8859-1. For example, Japanese user agents will default to a Japanese encoding that does not include the accented letters, so they may not see you text correctly unless you specified the encoding.

In case of conflict, the Content-Type charset declaration and the XML declaration have precedence over the meta charset statement, according to the HTML 4.01 and XHTML 1.0 specifications. [Ed. note: Is this true in practise? esp wrt IE?]

Use meta charset declarations as early as possible in the head element.

 IE(Win)  NNav  Opera 

This maximizes the likelihood that non-ASCII characters will be correctly recognized by the user agent.

The HTML spec says "The meta declaration must only be used when the character encoding is organized such that ASCII-valued bytes stand for ASCII characters (at least until the meta element is parsed). " [Ed. note: How true is this?]

For HTML use the lang attribute, and for XHTML use the lang and xml:lang attributes in the html tag.

 IE(Win)  NNav  Opera 

This sets the default language for the whole document. It can be overridden for portions of the document as required.

[Ed. note: Give reasons for use. ]

[Ed. note: Give an example.]

[Ed. note: What about the use of the meta statement? ]

Go to outline view...Return to top of contents...2.2 International layout considerations

Whenever possible, avoid HTML attributes with values of right and left. Use CSS in a linked stylesheet instead.

 IE(Win)  NNav  Opera 

Because difficult to localize - at least CSS is likely to minimize required changes.[Ed. note: Note that you can have a different style sheet per language. Give some examples and make it clear that this doesn't refer to rtl and ltr values.]

Whenever possible, avoid using CSS constructs that specify values of right and left. Use before and after if available.

 IE(Win)  NNav  Opera 

[Ed. note: This belongs in the CSS repository.]

Because difficult to localize [Ed. note: Note that before and after values are common in CSS3.]

3 Character sets, character encodings and entities

Go to outline view...Return to top of contents...3.1 Choosing a page encoding

Choose UTF-8 or another Unicode encoding for all content.

 IE(Win)  NNav  Opera 

When selecting a page encoding, consider both current and future localization requirements, and the benefits of using the same encoding across all pages and all languages. These considerations make the use of Unicode an attractive choice for the following reasons:

  • Unicode supports many languages, enabling the use of a single encoding across all pages and forms, regardless of language.

  • Unicode allows many more languages to be mixed on a single page than almost any other choice. If the set of languages to be represented on a single page cannot be represented directly by any single native encoding (such as ISO-8859-1, Shift-JIS, etc.), then Unicode is almost certainly the best choice.[Ed. note: How is this different from the previous point?]

  • For dynamically-generated pages, a single encoding for all pages eliminates the need for server-side logic to determine the character encoding for each page served.

  • For interactive applications using forms, a single encoding eliminates the need for server-side logic to determine the character encoding of incoming form data.

  • Unicode enables a form in one language (e.g. English) to accept input in a different language (e.g. Chinese).

  • Unicode (UTF-8) forms will be easier to migrate to XForms.[Ed. note: We should add some justification for this.]

UTF-8 and UTF-16 are both Unicode encodings. Since support for Unicode is currently limited to UTF-8 in many user agents, UTF-8 is usually the appropriate Unicode encoding. However, as user agent support for UTF-16 expands, UTF-16 will become an increasingly viable alternative.

Although there are other multi-script encodings (such as ISO-2022 and GB18030), Unicode generally provides the best combination of user agent and script support.

If you don't use a Unicode encoding, select an encoding that best supports the languages / characters to be included in the page text. [Ed. note: What does this mean? Does it mean, which maximizes the opportunity to directly represent characters and minimizes the need to represent characters by markup means such as character escapes? Does it include the idea that you should choose the most commonly used encoding for a region?]

 IE(Win)  NNav  Opera 

There are some situations where selecting a Unicode encoding is not practical. If content is encoded in a native encoding (legacy content or content originating from an external source) and the system lacks functionality for converting content between encodings, Unicode may greatly complicate implementation. If such a site is only required to serve single-script pages (containing languages that can be represented by a single native encoding), then the cost of using a Unicode encoding may outweigh the benefits. In this case, a native encoding (such as ISO-8859-1, Shift-JIS, etc.) may be a better choice.

Be sure to select an encoding that covers most [Ed. note: all? ]of the characters required for the content, and (if it is a form) all of the characters that must be accepted as input.

Check that user agents (all agents that must render the page) adequately support the page encoding that you have selected. If not, you might need to use a more widely supported encoding to achieve an adequate degree of user agent support.[Ed. note: Couldn't this be rolled into the previous technique?]

 IE(Win)  NNav  Opera 

Not all user agents support all page encodings, so it is important to understand which user agents must be able to render the page, and be sure that they have adequate support for the page encoding you have selected.

In general, user agents are most likely to support the commonly-used native character encodings for the major languages used on the web. Support for less commonly used encodings depends on the user agent. Older user agents, or user agents that operate under severe memory limitations, may not support UTF-8.

It is important to note that support for a given encoding does not necessarily imply support for all writing systems that encoding supports. For example, a user agent might support UTF-8, but not correctly display bidirectional Arabic text encoded in UTF-8. To display a page correctly, a user agents must support both the page encoding and the writing system.

Use character sets and encodings that will be accessible and common to your users.

 IE(Win)  NNav  Opera 

.[Ed. note: Point to an updated version of the table in hints & tips]

Resources:

Further information

Implementation guidelines

Reference links

Sources

Go to outline view...Return to top of contents...3.2 Specifying a page encoding

Where practical, declare the page's character encoding by setting the charset parameter in the HTTP Content-Type header.

 IE(Win)  NNav  Opera 

Since the HTTP Content-Type header has precedence, and is also the easiest information to retrieve (user-agents do not have to parse the resource to get it), it is typically the preferred way to provide the character encoding for an HTML/XHTML document.

According to the HTML specification, in a case of conflict the HTTP charset declaration has the highest priority of all means of declaring the character set.

The reason you should do this 'where practical' is that pages may need to be viewed from a hard drive or CD, or some other way that doesn't involve interaction with the server. To provide for such cases, you should also declare the character encoding within the document itself.

Care should also be taken to ensure that the server-side settings are maintained if the file is moved or the server technology is changed.

For XHTML served as text/html, where practical use an XML declaration with an encoding attribute.

 IE(Win)  NNav  Opera 

To do this, use an XML declaration as shown below at the top of the file, and assign an IANA charset name to the encoding label of the declaration.

Example:

<?xml version="1.0" encoding="UTF-8"?>

The checklist item above uses the phrase 'where practical' because authors serving XHTML as text/html often choose not to include the XML declaration. This is because the declaration can cause display problems for some HTML browsers. For example, anything that appears before the DOCTYPE declaration forces Internet Explorer browsers, including version 6, into 'quirks' mode rather than 'standards' mode.

Because an XHTML document served as text/html is actually handled as HTML, the XML declaration is not actually required when the document is served. Note, however, that the XHTML specification recommends the use of both XML declaration and the meta charset declaration when XHTML is served as text/html.

In theory it is not necessary to specify the character encoding in an XML declaration for documents encoded in UTF-8 and UTF-16, since the XML parser treats these as the default. In practise, however, it is a good idea to label the document explicitly (as shown in the example above). For example, developers, testers, or translation production managers may want to perform a visual check of a document, or process the document using tools other than XML parsers.

You should declare the encoding inside the document even if the HTTP Content-Type parameter has been sent by the server. This ensures that the character encoding is always declared, even if the document is at some point not read from that server (eg. a local copy is read from disk, or the file is moved to another server that is not set up to serve the Content-Type parameter).

According to the XHTML 1.0 specification, in XHTML-conforming user agents, the value of the encoding declaration of the XML declaration takes precedence over the meta charset statement. It has a lower priority, however, than the HTTP Content-Type parameter.

For XHTML served as application/xhtml+xml, always use an XML declaration with an encoding attribute.

 IE(Win)  NNav  Opera 

To do this, use an XML declaration as shown below at the top of the file, and assign an IANA charset name to the encoding label of the declaration.

Example:

<?xml version="1.0" encoding="UTF-8"?>

If you are serving XHTML as application/xhtml+xml, the encoding attribute is mandatory unless you are using UTF-8 or UTF-16 or declaring the encoding in the HTTP header.

In theory it is not necessary to specify the character encoding in an XML declaration for documents encoded in UTF-8 and UTF-16, since the XML parser treats these as the default. In practise, however, it is a good idea to label the document explicitly (as shown in the example above). For example, developers, testers, or translation production managers may want to perform a visual check of a document, or process the document using tools other than XML parsers.

You should declare the encoding inside the document even if the HTTP Content-Type parameter has been sent by the server. This ensures that the character encoding is always declared, even if the document is at some point not read from that server (eg. a local copy is read from disk, or the file is moved to another server that is not set up to serve the Content-Type parameter).

According to the XHTML 1.0 specification, in XHTML-conforming user agents, the value of the encoding declaration of the XML declaration takes precedence over the meta charset statement. It has a lower priority, however, than the HTTP Content-Type parameter.

The meta charset declaration is not needed when XHTML is served as application/xhtml+xml.

For HTML documents and XHTML documents served as text/html, always use the meta element to explicitly declare the document's character encoding.

 IE(Win)  NNav  Opera 

To do this, assign an IANA charset name as the charset value of a meta http-equiv statement.

Example:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xml:lang="en" lang="en">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

<title>Sample document</title>

...

This is good practise even if the character encoding has already been specified in the HTTP Content-Type parameter or any XML declaration (in XHTML). It ensures that the character encoding is always declared even if the document is at some point not read from that server (eg. a local copy is read from disk, or the file is moved to another server that is not set up to serve the Content-Type parameter).

Note that the XHTML specification recommends that the character encoding be declared in both the meta charset declaration and the XML declaration.

Note also that you should include a character encoding declaration even if your document uses a basic Latin encoding such as ISO 8859-1. For example, Japanese user agents will default to a Japanese encoding that does not include the accented letters, so they may not see you text correctly unless you specified the encoding.

In case of conflict, the Content-Type charset declaration and the XML declaration have precedence over the meta charset statement, according to the HTML 4.01 and XHTML 1.0 specifications. [Ed. note: Is this true in practise? esp wrt IE?]

Use meta charset declarations as early as possible in the head element.

 IE(Win)  NNav  Opera 

This maximizes the likelihood that non-ASCII characters will be correctly recognized by the user agent.

The HTML spec says "The meta declaration must only be used when the character encoding is organized such that ASCII-valued bytes stand for ASCII characters (at least until the meta element is parsed). " [Ed. note: How true is this?]

Use the preferred names from IANA's charset registry.

 IE(Win)  NNav  Opera 

The IANA charset registry shows a name plus a list of aliases for each registered charset value. One of these is identified as the preferred MIME name. Wherever you declare the character encoding, use the preferred MIME name in the charset value.

This maximizes the likelihood of interoperability.

Resources:

Further information

Reference links

Sources

Go to outline view...Return to top of contents...3.3 Referring to specific characters

Avoid escapes when the characters to be expressed are representable in the character encoding of the document.

 IE(Win)  NNav  Opera 

[Ed. note: Provide an overview of how to use escapes: hex / decimal NCRs, and entities - use is ok for invisible characters or others - explain what the exceptions might be ]

When using escapes, use the hexadecimal form.

 IE(Win)  NNav  Opera 

Since character set standards usually list character numbers as hexadecimal.

If, for a specific application, it becomes necessary to refer to characters outside [ISO10646], characters should be assigned to a private zone to avoid conflicts with present or future versions of the standard. Use of private use characters is highly discouraged, however, for reasons of portability.

 IE(Win)  NNav  Opera 

tbd

[Ed. note: Add something about the use of inline images to represent characters ]

 IE(Win)  NNav  Opera 

Discuss

Resources:

Sources

4 Fonts

Go to outline view...Return to top of contents...4.1 Choosing & specifying fonts

Do not use <font> tags - use CSS styles instead.

 IE(Win)  NNav  Opera 

Note that <font> and <basefont> tags are deprecated in the HTML4.01 Recommendation.

Easier maintenance

Faster translation AND localization.

[Ed. note: Describe the evils of using <font> to cheat on the charset and represent other scripts.]

Always use the serif and sans-serif fallbacks

 IE(Win)  NNav  Opera 

Don't assume you know which fonts will be available on the client.

 IE(Win)  NNav  Opera 

Also don't assume that the font you've chosen will contain the characters needed for localized pages

Don't rely on text just fitting in a space

 IE(Win)  NNav  Opera 

tbd

Go to outline view...Return to top of contents...4.2 Dealing with undisplayable characters

Some guidelines for content authors who know that users won't have all the necessary fonts.

 IE(Win)  NNav  Opera 

tbd

5 Specifying the language of content

Go to outline view...Return to top of contents...5.1 Specifying the overall language of a document

For HTML use the lang attribute, and for XHTML use the lang and xml:lang attributes in the html tag.

 IE(Win)  NNav  Opera 

This sets the default language for the whole document. It can be overridden for portions of the document as required.

[Ed. note: Give reasons for use. ]

[Ed. note: Give an example.]

[Ed. note: What about the use of the meta statement? ]

Resources:

Further information

Go to outline view...Return to top of contents...5.2 Identifying language change

Use the lang and xml:lang attributes around text in a language other than that of the whole document.

 IE(Win)  NNav  Opera 

Give reasons for use. Extremely important for screen readers. Adaptation of styles.

Give an example.

Resources:

Further information

Go to outline view...Return to top of contents...5.3 Specifying the language of a link destination

Use the hreflang attribute on the a element.

 

Need to think about this - don't think it is supported by browsers.

Do we include detail here or under section on links?

Resources:

Further information

Go to outline view...Return to top of contents...5.4 Specifying language codes

Follow the guidelines in RFC3066.

 IE(Win)  NNav  Opera 

Note that the HTML spec still says rfc1766, but this has been made obsolete by rfc3066.

Explain the basic principles here.

Use the two-letter ISO 639 codes for the language code wherever possible, rather than the 3-letter codes.

 IE(Win)  NNav  Opera 

RFC3066 specifies that the two letter codes should be used where available, since this aids interoperability, and increases the likelihood of general recognition by browsers.

Resources:

Sources

6 Handling bidirectional text

'Bidirectional', or 'bidi', text refers to text written using a script such as Arabic or Hebrew. In such scripts the text flows predominantly from right to left, but embedded numbers or text in other scripts (such as Latin script) still runs left to right.

Go to outline view...Return to top of contents...6.1 Enabling easy localization for RTL scripts

Whenever possible, avoid HTML attributes with values of right and left. Use CSS in a linked stylesheet instead.

 IE(Win)  NNav  Opera 

Because difficult to localize - at least CSS is likely to minimize required changes.[Ed. note: Note that you can have a different style sheet per language. Give some examples and make it clear that this doesn't refer to rtl and ltr values.]

Whenever possible, avoid using CSS constructs that specify values of right and left. Use before and after if available.

 IE(Win)  NNav  Opera 

[Ed. note: This belongs in the CSS repository.]

Because difficult to localize [Ed. note: Note that before and after values are common in CSS3.]

Go to outline view...Return to top of contents...6.2 General use of bidi markup

Do not use CSS styling to control directionality in XHTML/HTML. Use markup.

 IE(Win)  NNav  Opera 

Because directionality is an integral part of the document structure, markup should always be used to set the directionality for a document or chunk of information, or to indicate places in the text where the Unicode bidi algorithm is insufficient to achieve desired directionality.

The CSS2 specification recommends the use of markup for bidi text in HTML. In fact it goes as far as to say that conforming HTML user agents may ignore CSS bidi properties. This is because the HTML specification clearly defines the expected behavior of user agents with respect to the bidi markup.

See CSS vs. markup for bidi support for a fuller explanation.

Only use bidi markup where it is needed.

 IE(Win)  NNav  Opera 

Once you have established the appropriate directionality for the html element you will only need to apply bidi markup to a block element if you want that element's directionality to be different. The same applies for inline markup. Do not use inline bidi markup unless the Unicode bidi algorithm is insufficient on its own.

The following Arabic example shows bad usage. None of the dir attributes are needed if dir="rtl" was added to the html element. Removing them will significantly simplify the document, and reduce bandwidth - which may be an important consideration in countries where Arabic is spoken.

Example:

Bad practise. Do not copy!

<h2 dir="rtl">القاموس</h2>

<dl>

<dt dir="rtl">المنالية</dt>

<dd dir="rtl">سهولة منال للويب من قبل الجميع بصرف النّظر عن إعاقةهم . </dd>

<dt dir="rtl">برنامج التصديق</dt>

<dd dir="rtl">

أو "الفاليديتور" أداة للتّحقّق من صلاحيّة صفحة ويب. على سبيل المثال، للتّحقّق من صلاحيّة

<span dir="ltr">HTML</span> ، يمكن أن تستخدم بزنامج تصديق

<span dir="ltr">W3C</span>

</dd>

<dt dir="rtl">التّدويل</dt>

<dd dir="rtl">

تدويل الويب يسمح و يجعله سهل لاستخدام موقعك باللّغات و السّيناريوهات و الثّقافات المختلفة.

</dd>

</dl>

The Unicode Bidirectional Algorithm is applied to text that is stored in logical order, and determines the appropriate display direction of a sequence of characters. It does this on the basis of semantics associated with those characters by the Unicode Standard.

Example:

The following Arabic text contains the number 1996 that runs left to right within the overall right to left flow of the Arabic letters. No special markup or styling is needed to achieve this. The bidirectional algorithm alone is enough.

بدأ تطوير إكس إم إل في 1996 و صارت...

Occasionally the Unicode bidirectional algorithm is not sufficient to correctly order chunks of embedded text. Alternatively, you may want to override the effects of the bidirectional algorithm for a part of the page. In these cases you can apply additional markup to produce the ordering you want.

Resources:

Background information

Sources

Go to outline view...Return to top of contents...6.3 Basic setup for pages in RTL scripts

Add dir="rtl" to the html tag any time the overall document direction is right-to-left.

 IE(Win)  NNav  Opera 

This will cause block elements and table columns to start on the right and flow from right to left. All block elements in the document will inherit this setting unless it is explicitly overridden.

No dir attribute is needed for documents that have a base directionality of ltr, since this is the default.

Having established the directionality at the html tag level, you should not use the dir attribute on other elements unless you want to change the directionality for that element. Unnecessary use of the dir attribute impacts bandwidth and potentially creates unnecessary additional work for page maintenance.

User Agent Notes:
IE5

Microsoft recommends that that the dir attribute be attached to the html element rather than the body element for several reasons relating to the functionality associated with the browser.

User Agent Notes:
IE5+

In Internet Explorer adding the dir attribute to the html tag also moves the scroll bar to the left of the browser window.

Do not add dir="rtl" to the body tag.

 IE(Win)  NNav  Opera 

Although the HTML specification recommends the use of the dir attribute on the html element, this guideline is motivated more by practical considerations relating to user agent behavior.

According to the Microsoft article Authoring HTML for Middle Eastern Content, the following behaviors can only be expected in Internet Explorer 5 if the dir attribute is on the html element, rather than the body element.

  • The OLE/COM ambient property of the document is set to AMBIENT_RIGHTTOLEFT

  • The document direction can be toggled through the document object model (DOM) (document.direction="ltr/rtl")

  • An HTML Dialog will get the correct extended windows styles set so it displays as a RTL dialog on a Bidi enabled system.

  • If the document has vertical scrollbars, they will be used on the left side if dir="rtl".

[Ed. note: check whether similar things apply to other user agents]

Use logical order, not visual ordering for Hebrew.

 IE(Win)  NNav  Opera 

'Visual ordering' of text was common for old user agents that didn't support the Unicode bidirectional algorithm. Text was stored in the source code in the same order you would expect to see it displayed. This also involved such things as disabling any line wrapping, explicit right-alignment of text in paragraphs and table cells, and reverse-ordering of table columns when translating from English to a language using a bidi script. The result is very fragile code that is difficult to maintain. For example, if you want to add a few words in the middle of a paragraph, you would have to move text to and from every line that followed it in the paragraph.

Visually ordered bidirectional HTML does not conform to the HTML specification.

With 'logical ordering' text is stored in memory in the order in which it would normally be typed (and usually pronounced). The Unicode bidirectional algorithm is then applied by the browser to render the correct visual display.

Visual ordering isn't really seen much for Arabic. Since the Arabic letters are all joined up there was a stronger motivation on the part of Arabic implementers to enable the logical ordering approach.

If using an ISO character encoding for Hebrew, choose iso-8859-8-i and use logical ordering.

 IE(Win)  NNav  Opera 

It is usually best to use an Unicode encoding, such as UTF-8. This technique applies if, for some reason, you choose to serve your Hebrew page in an ISO encoding instead.

According to RFC1555 and RFC1556, 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. 'Visual' refers to the practise of typing in the Hebrew characters in reverse order and preventing automatic line breaks. Formatting the document visually in this way is typically done to ensure reasonable display on older user agents that do not handle bidirectionality. Such documents do not conform to the HTML specification. 'Implicit' is also called logical ordering, and refers to an approach where all characters in memory in the order in which it would normally be typed. Correct ordering for display is then done by a special algorithm (this is the preferred approach). 'Explicit' refers to the use of explicit markers in the text to indicate directional changes.

The charset parameter value ISO-8859-8 for Hebrew denotes visual ordering, ISO-8859-8-i denotes implicit bidirectionality, and ISO-8859-8-e denotes explicit directionality.

Because HTML uses the Unicode bidirectional 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.

Contrary to what is said in RFC1555 and RFC1556, ISO-8859-6 (Arabic) is not visual ordering.

Resources:

Further information

Background information

Reference links

Sources

Go to outline view...Return to top of contents...6.4 Changing the directionality of a block element

Add the dir attribute to a block level element (only) to change its directionality.

 IE(Win)  NNav  Opera 

The following example illustrates the effect of applying a change in directionality to a block level element using the dir attribute.

Example:

The following paragraph inherits the LTR directionality of this page, and its source contains some Hebrew text, followed by punctuation, followed by a graphic.

להוביל את הרשת למיצוי הפוטנציאל שלה…  Small picture of a globe.

The following is exactly the same code, but with an explicit dir="rtl" added to the paragraph tag to turn this into a right-to-left paragraph embedded in this left-to-right page.

להוביל את הרשת למיצוי הפוטנציאל שלה…  Small picture of a globe.

Note, in particular, that the positions of the image and punctuation in the example above change relative to the text, because the overall directional flow has been changed. Note also, however, that the Hebrew characters are still read in the same direction. Their sequence is determined by the Unicode bidirectional algorithm, not by the dir attribute.

The content of all nested block elements will inherit directionality (unless of course a nested element explicitly changes its directionality using dir). Remember that the base directionality for a document should already be established by the html element. There is no need to add dir attributes to block level elements unless you want to apply a different direction to that set by the html tag or an explicit setting on a parent block element.

Visual user agents that support bidirectional display will typically right-align block elements in a rtl context, and vice versa. (See the example above.)

The dir attribute setting also affects the flow of columns in a table.

Example:

The following table element has a dir attribute set to rtl.

123
مكتب W3C הישראליمكتب W3C הישראליمكتب W3C הישראלי

Here is the same table element with the dir attribute removed. The directionality of the columns is now set by the next ancestor element that specifies directionality - in this case the default ltr setting of the html tag of this document.

123
مكتب W3C הישראליمكتب W3C הישראליمكتب W3C הישראלי

Note how the cells inherit the directionality set for the table. This produces the alignment of text in the cell, the order of text relative to the number, and the position of the question mark.

Note also that in most browsers, unlike other block elements, adding a dir attribute to the table will not cause the table to be aligned differently. It will only affect the order of columns and table content. If you want the table to be aligned with the other side of the content area you will need to wrap the table in another block element (eg. a div) that carries a dir attribute.[Ed. note: Check that this applies for Mac browsers.]

Go to outline view...Return to top of contents...6.5 Mixing text direction inline

Use a Unicode right-to-left mark (RLM) or left-to-right mark (LRM) to make neutral characters such as punctuation and spaces appear in the right place when they fall between different directional runs.

 IE(Win)  NNav  Opera 

You need to be familiar with the concepts in What you need to know about the bidi algorithm and inline markup to understand this technique.

Unfortunately, the bidirectional algorithm may not always produce the desired result with regard to the placement of punctuation. For instance, the overall context of the example below is LTR. If we introduce some punctuation between the Arabic and Latin letters it will produce the following (undesirable) result.

Example:

The title is "مفتاح معايير الويب!" in Arabic.

The exclamation mark is part of the Arabic phrase and should have appeared to its left. It appears to the right because it is between an Arabic and Latin character and the overall paragraph direction is LTR. It is therefore treated as part of the English text.

An easy way to fix this is to insert the Unicode character U+200F, called the RIGHT-TO-LEFT MARK, after the exclamation mark. There is a similar character, U+200E, called the LEFT-TO-RIGHT MARK.

The best way to represent these characters is with the pre-defined HTML character entities, &rlm; and &lrm;.

Now with two strong RTL characters on either side, the exclamation mark too will be treated as part of the RTL directional run and we will get the following (correct) result.

Example:

The title is "مفتاح معايير الويب!‏" in Arabic.

Note that it is possible to use actual Unicode characters or Numeric Character References (ie. &#x200E; and &#x200F;) rather than the character entities mentioned above. The character entity is recommended because it provides maximum clarity in the code. A character code would not be visible, and a numeric value may be easily mistaken.

[Ed. note: Actually that's not quite true. It looks fine in a LTR paragraph (see above), but not in a RTL context, where the entity name falls foul of the same problem! see below. You may be able to avoid this in some cases by breaking the line - as long as this doesn't introduce unwanted spaces.]

Example:

مشس هخصث خهس title in english!&lrm; تخت تخهثز.

مشس هخصث خهس title in english!&#x200E; تخت تخهثز.

Use a Unicode right-to-left mark (RLM) or left-to-right mark (LRM) to correctly order separate runs of same direction text separated by neutral characters such as punctuation and spaces.

 IE(Win)  NNav  Opera 

You need to be familiar with the concepts in What you need to know about the bidi algorithm and inline markup to understand this technique.

The Unicode characters RLM (right-to-left mark) and LRM (left-to-right mark) can be useful to achieve the correct ordering of text items that are only separated by directionally neutral characters. We will show two examples of this.

In our first example, below, the list order is incorrect because the first two Arabic words should be reversed and the intervening comma, which is part of the English text, should appear immediately to the right of the first word. The reason for the failure is that, with a strongly typed right-to-left (RTL) character on either side, the bidirectional algorithm sees the neutral comma as part of the Arabic text.

Example:

Incorrect:

The names of these states in Arabic are مصر, البحرين and الكويت respectively.

Corrected:

The names of these states in Arabic are مصر,‎ البحرين and الكويت, respectively.

The correct result was obtained by simply placing a &lrm; entity immediately after the comma. This has the effect of placing the neutral comma between two strongly typed characters, one left-to-right and the other right-to-left. Because neutral characters in this position take on the directionality of the overall context (here the paragraph), the bidi algorithm will now see it as part of the English left-to-right flow and will see the two Arabic words as separate.

In the second example, this time in a RTL Hebrew paragraph, the beginning of the sentence looks a real mess. This is because the text from "W3C" to "Consortium" is seen as a single directional run of LTR characters. (The second parenthesis from the right falls between LTR and RTL characters, so assumes the directionality of the paragraph - RTL.)

Example:

Incorrect:

W3C - (World Wide Web Consortium) מעביר את שירותי הארחה באירופה ל - ERCIM.

Correct:

W3C -‏ (World Wide Web Consortium) מעביר את שירותי הארחה באירופה ל - ERCIM.

It is very simple to obtain the correct result. Simply put a &rlm; entity immediately after the hyphen. This causes the hyphen and the nearby parenthesis to be seen as part of the paragraph's text flow.

Note that the dir attribute is not appropriate to resolve this case.

Use the dir attribute on an inline element to resolve problems with nested directional runs.

 IE(Win)  NNav  Opera 

At a simple level the Unicode bidirectional algorithm takes care of the reordering of inline text, but where there is nesting of directionality the dir attribute may need to be used.

The Unicode bidirectional algorithm organizes characters into directional runs - sequences of characters with the same directionality. Directionally neutral characters such as spaces and punctuation take on the directionality of surrounding characters, allowing directional runs to span several words. In the example below there are three directional runs - English, Arabic, and English. These are ordered according to the prevailing directionality of the paragraph - in this case left-to-right.

Example:

The title is مفتاح معايير الويب in Arabic.

Unfortunately, the bidirectional algorithm alone does not produce the desired result if one of the directional runs contains mixed direction text, as can be seen in the following example.

The incorrect line of text is coded as a simple sequence of characters without any inline markup. Note that the order of the two Hebrew words is correct, but the text "W3C" should appear on the left hand side of the quotation and the comma should appear between the Hebrew text and "W3C".

Example:

Incorrect:

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

Correct:

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

To get the correct result we have to create a new 'embedding level' by surrounding the text within the quote marks with a span element and setting its dir attribute to rtl as shown here. (The language information has been omitted to make the example clearer.)

Example:

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

This causes the comma to take on the same RLT directionality as the whole span, and orders the Hebrew directional runs appropriately.

Note that we have used a span element to carry the dir attribute in this case. If the quote had already been surrounded by an element, the dir attribute should be attached to that. A span element should only be used where there is nothing else available.

Note also that we placed the span element inside the quotation marks, since these are a part of the English text.

[Ed. note: Note that it may make sense to use markup rather than control codes, but it certainly doesn't make editing any easier unless the editing tool understands the markup you are applying and reorders the text appropriately. ]

For attribute text or element text that allows no internal markup, use Unicode control characters for bidirectional control.

 IE(Win)  NNav  Opera 

@@ make sure to refer to the title element

Do not use Unicode control characters for bidirectional control if markup is available.

 IE(Win)  NNav  Opera 

There are a number of control characters in Unicode that can be used to create the same effect as markup for bidirectional text. These are:

  • U+202A LEFT-TO-RIGHT EMBEDDING

  • U+202B RIGHT-TO-LEFT EMBEDDING

  • U+202D LEFT-TO-RIGHT OVERRIDE

  • U+202E RIGHT-TO-LEFT OVERRIDE

  • U+202C POP DIRECTIONAL FORMATTING

Both Unicode in Markup Languages and the HTML 4.01 specification advise against using these when markup is available, and they particularly advise against mixing control codes and markup.

[Ed. note: The references below need checking (esp for surviving ref to CSS)]

Do not leave white space at the end of inline elements that mark a directional boundary.

 IE(Win)  NNav  Opera 

[Ed. note: Summarise and point to the bidi space Q&A]

Resources:

Further information

Sources

Go to outline view...Return to top of contents...6.6 Handling parentheses & other mirrored characters

Treat mirrored characters as if any word left in the name meant 'opening', and right meant 'closing'.

 IE(Win)  NNav 

The shape of the glyphs used for a pair of mirrored characters will be determined at run time according to the directional context in which they appear.

Go to outline view...Return to top of contents...6.7 Overriding the Unicode bidirectional algorithm

Use the bdo element to force the directionality of a sequence of inline characters.

 IE(Win)  NNav  Opera 

bdo stands for 'bidirectional override'. This inline element can be used to override the Unicode bidirectional algorithm if the dir attribute doesn't produce the desired result or if you want to produce a different result.

Example:

Illustrations of the characters as stored in memory in earlier examples are produced by simply applying a bdo tag. This causes the characters to flow left to right, regardless of the directionality of the characters involved. For instance, an example showing how text is stored in the computer's memory such as

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

can be produced using the following underlying code

<p><bdo dir="ltr">The title says "פעילות הבינאום" in Hebrew.</bdo></p>

Without the bdo tag, the Unicode bidirectional algorithm would have produced the following result. Note how the characters in the Hebrew words run in a different direction.

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

7 * Handling vertical text

8 * Text formatting

9 * Lists

10 * Tables

11 * Links

12 * Objects

13 * Images

14 Handling data that varies by locale

Go to outline view...Return to top of contents...14.1 Date & time

Use the full form of the year.

 IE(Win)  NNav  Opera 

The two digit year can cause confusion in parts of the world where multiple calendars are used. In these locations it may not be clear whether you are referring to the year using the local calendar or not.

Use words (abbreviated if necessary) for the month.

 IE(Win)  NNav  Opera 

Ambiguous dates cause confusion.

Example:

The date

02/03/04

may be March 4th, 2002 (in Japan,...), 2nd of March, 2004 (in Europe) and February 3rd, 2004 (in the USA). It would be better to write this as something like

02 mar 2004

For forms, use structured fields or popup menus for date and time input.

 IE(Win)  NNav  Opera 

These make it clear for the user what order and format to use for data entry, and guarantee that the time will be recognized by the script, database or person that receives the information.

Example:

Add an example of a structured field approach.

Example:

Add an example of a popup approach.

Resources:

Implementation guidelines

Background information

Sources

15 Forms

While this section awaits content you can find a W3C Internationalization FAQ that answers the question, What is the best way to deal with encoding issues in forms that may use multiple languages and scripts?

16 * Keyboard shortcuts

17 * Writing source text

18 * Navigation

19 * File management

20 * Supplying data for localization

A Acknowledgements

The following GEO Task Force members have contributed their time and valuable comments to shaping these guidelines:

Phil Arko, Steve Billings, Wendy Chisholm, Andrew Cunningham, Martin Dürst, Lloyd Honomichl, Russ Rolfe, Peter Sigrist, Tex Texin, Najib Tounsi

B References

CharMod
M. J. Dürst, F. Yergeau, R. Ishida, M. Wolf, T. Texin, Character Model for the World Wide Web 1.0, Working Draft in Last Call . (See http://www.w3.org/TR/charmod/.)
CSS2
Bert Bos, Håkon Wium Lie, Chris Lilley, Ian Jacobs, Eds., Cascading Style Sheets, level 2 (CSS2 Specification), W3C Recommendation. (See http://www.w3.org/TR/REC-CSS2.)
HTML 4.01
Dave Raggett, Arnaud Le Hors, Ian Jacobs, Eds., HTML 4.01 Specification, W3C Recommendation. (See http://www.w3.org/TR/html401.)
IANA
Internet Assigned Numbers Authority, Official Names for Character Sets. (See http://www.iana.org/assignments/character-sets.)
RFC1555
H. Nussbacher and Y. Bourvine, Hebrew Character Encoding for Internet Messages, December 1993. (See http://www.ietf.org/rfc/rfc1555.txt
RFC1556
H. Nussbacher, Handling of Bi-directional Texts in MIME, December 1993. (See http://www.ietf.org/rfc/rfc1556.txt
RFC2616
R. Fielding et al., Hypertext Transfer Protocol -- HTTP/1.1, June 1999. (See http://www.ietf.org/rfc/rfc2616.txt
Unicode
The Unicode Consortium, The Unicode Standard, Version 3, ISBN 0-201-61633-5, as updated from time to time by the publication of new versions. (See http://www.unicode.org/unicode/standard/versions for the latest version and additional information on versions of the standard and of the Unicode Character Database).
UXML
Martin Dürst and Asmus Freytag, Unicode in XML and other Markup Languages, Unicode Technical Report #20 and W3C Note. (See http://www.w3.org/TR/unicode-xml.)
XHTML 1.0
W3C HTML Working Group, XHTML™ 1.0 The Extensible HyperText Markup Language (Second Edition), W3C Recommendation. (See http://www.w3.org/TR/xhtml1/.)