Tutorials Bugs Masterclass Free stuff Test pages Proposals

Basic concepts

Advanced concepts

RichInStyle.com HTML 4 guide - Languages

Lang

In order to specify the language that an element is in, you use the lang attribute. For example, <P lang="de"> (German). Languages inherit, so if you specify <HTML lang="en-us"> (US English), this will inherit to all descendant elements.

Languages are specified to assist search engines and to help browsers render your page in a language-appropriate manner.

Language codes take the form of a two letter primary language optionally followed by a hyphen and a subcode. The primary language is something like 'en' (English), and the subcode the regional dialect.

It is also possible specify a language using HTTP by setting 'Content-Language: language'; e.g., Content-Language: en-us.

Bidirectionality (bidi)

The dir attribute

The dir attribute specifies the direction of directionally neutral text (that is to say text for which there is no inherent directionality) and of tables. For example, <Q dir="rtl">.

Primarily the dir attribute is associated with block-level elements. Dir is inherited to block-level descendants. Thus every block-level element has a dir. For example, if your browser is right-to-left this P will have inherited dir="rtl". That doesn't mean that the text will go right-to-left however, because this text is inherently left-to-right so it is displayed left-to-right.

Why then, you might ask, is dir needed at all. The answer is that the bidirectional algorithm can only cope with one level of embedding (i.e., of one level with different direction). For example, if this P element had dir="rtl", and contained some right-to-left text inside some left-to-right text (on a right-to-left element), because there is more than one level of embedding, to get correct directionality on the second level of embedding, it must be given dir="rtl" to get correct results.

BDO

Sometimes text might already have been put in visual order; for example, if you have right-to-left characters that have already been placed right-to-left in the document source (e.g., assuming 'Hello' is a right-to-left word, 'olleH'). To stop the renderer inverting this again, you would simply put <BDO dir="direction"></BDO> around the the text. This stops implicit reordering and simply renders the whole sequence left-to-right.

That's the end of the HTML guide! I now suggest that you learn about CSS, or go the RichInStyle.com front page to see what else is on offer.