Intended audience: HTML and CSS content authors implementing pages in right-to-left scripts such as Arabic and Hebrew, or having to deal with embedded right-to-left script text.
This tutorial gathers together and organizes pointers to articles that, taken together, help you understand the essential aspects of how to work with languages in right-to-left scripts and bidirectional text when authoring HTML and CSS.
Add a dir
attribute to the html
tag to set the default base direction of your page if it is right-to-left. Use the dir
attribute on block elements within the page only where you need to change the base direction.
For inline text, tightly wrap all opposite-direction phrases in markup that sets their base direction.
Use dir=auto
to automatically set the base direction of form fields, pre
elements or text inserted into the page. Use the dirname
attribute if you need to pass information about the base direction of form input to the server.
Avoid using CSS or Unicode control codes for managing direction where you can use markup.
Use logical ordering of bidirectional text, rather than visual ordering, and let the Unicode Bidirectional Algorithm take the strain.
In this section we cover the basics of markup for text direction.
Unicode Bidirectional Algorithm basics provides a gentle introduction to how the bidi algorithm works, highlighting concepts and terminology that you'll need to understand how to work with bidirectional text.
Structural markup and right-to-left text in HTML looks at basic usage of the dir
attribute at the document level and for structural markup in HTML, eg. things like paragraphs, tables, and forms. It also looks at new developments in HTML5 for dealing with direction in form elements, pre
elements and inserted text.
Inline markup and bidirectional text in HTML begins by describing situations in which the Unicode Bidirectional Algorithm needs help from markup. The Unicode Bidirectional Algorithm is the basis for directional control of text in all browsers, but it has its limitations, and those need to be met with markup. The article looks at the problems and proposes simple solutions. This is somewhat more complicated than the previous article, because it is where you have to handle bidirectional text.
Visual vs. logical ordering of text compares visual vs. logical approaches to storing bidirectional text and makes the case for the logical model. These days you are generally unlikely to have to deal with visually-ordered content.
Generally speaking you should manage text direction in HTML using markup rather than CSS or Unicode control characters, although there are places where the latter is the only resort. These articles look into the reasons for this in detail.
CSS vs. markup for bidi support
Unicode controls vs. markup for bidi support discusses why markup is better than Unicode control characters, where it is available.
Using Unicode controls for bidi text explains how to use Unicode control characters where they are the only option.
Related links, Authoring web pages