Language specific styling: direction

Posted
August 2 2005

In the series of language specific styling, this article will focus on writing direction. Before we start, it is important to realize one thing: languages do not have a direction � scripts do. Some languages can be written in more than one script, respecting the script�s direction. Although script codes are standardized (iso 15924), they are not � yet � used in markup for that purpose. Therefor, it is important to supply sufficient dir attributes via markup, on top of the language declarations.


Default styles

Let�s focus on styling the different values of the dir attribute first. Not only will these function as a fallback; they will actually take preference over any language specific rules that will be applied (hence the !important rules).

In html 4, we know two possible values for the dir attribute, being ltr and rtl. On top of that, we know the bdo element. This results in the following style rules:

bdo { unicode-bidi: bidi-override !important }
[dir="ltr"] { direction: ltr !important; unicode-bidi: embed !important }
[dir="rtl"] { direction: rtl !important; unicode-bidi: embed !important }

In the current xhtml 2 specifications, we have two more possible values for the attribute dir, to which we can apply the following � more convenient � style rules:

[dir="lro"] { direction: ltr; unicode-bidi: bidi-override }
[dir="rlo"] { direction: rtl; unicode-bidi: bidi-override }

Directional languages

As mentioned before, languages don�t have a direction, and script codes are not used in current markup standards as such. In your own flavor of xml you could have a script attribute, to which you could apply the following style rules:

[script="Arab"] { direction: rtl }
[script="Cyrl"] { direction: ltr }
[script="Latn"] { direction: ltr }
/* etcetera */

�but, in today�s world [wide web] of html and xhtml, this is not an option, leaving us with little to work with. Little, but not nothing. There are language that can only be written using one script (or one group of scripts that are either written left to right, or right to left). Here are some of those language. (Note how some of them actually represent the name of a script.)

Languages and directions
LanguageDirection
Etcetera.
ArabicRight to left
BengaliLeft to right
HebrewRight to left
LatinLeft to right
TamilLeft to right
TengwarLeft to right

This can be translated to the following style rules (using Codes for the Representation of Names of Languages):

:lang(ar) { direction: rtl }
:lang(bn) { direction: ltr }
:lang(he) { direction: rtl }
:lang(la) { direction: ltr }
:lang(ta) { direction: ltr }
:lang(x-tengwar) { direction: ltr }

Ideographic languages

From FAQ: Script direction & languages:

Ideographic languages (e.g. Japanese, Korean, Chinese) are more flexible in their writing direction. They are generally written left-to-right, or vertically top-to-bottom (with the vertical lines proceeding from right to left). However, they are occasionally written right to left. Chinese newspapers sometimes combine all of these writing directions on the same page.

From this, we can conclude that the writing direction in these scripts may be inherited. The following style rule does exactly that:

:lang(ja), :lang(ko), :lang(zh) { direction: inherit }

Final fallback

User agents are perfectly capable of using their internal defaults as an ultimate fallback, but � for the sake of completeness � here�s an final fallback, css wise:

:root { direction: ltr }
:root * { direction: inherit }
ACJ

Comments

0 comments so far.

Comment

Identify
Remember Me?
Note
Markup allowed. Linebreaks and paragraphs are automatically converted. Email and ip addresses are logged but never shared with third parties. Comments are not moderated on opinion or use of language, but on relevance. I hate spam with a passion.