XHTML » XHTML Core Tag » dir


The dir attribute is used to declare the direction that the text should run, either left to right (default) or right to left. This allows the internationalization of HTML since several important foreign languages read right to left, such as Chinese and Hebrew.

Also, see the lang core attribute that defines the language being used. However, note that using lang by itself does not specify language direction.
If used as an attribute of the HTML tag, it will apply to the entire document. When used with other tags, it only applies to the text under the influence of that tag. For example, when used with the table tag, the first column of the table will start on the right side and each additional column will be farther to the left.
This attribute should not be used to simply reverse a string. That is best done by using the VBScript StrReverse( ) function.
You may only use the following values:
The ltr value, which directs the text to flow from left to right, is the default.

The rtl value directs the text to flow from right to left.

Note that .html texts that contain foreign languages that use special characters will have to be saved as a Unicode file, rather than as an ANSI file, in order for the characters to be properly displayed. Please be aware that some browsers may not be capable of correctly displaying a Unicode file.


<?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 xmlns="http://www.w3.org/1999/xhtml" dir="rtl" xml:lang="he" lang="he">
<title>DevGuru XHTML dir attribute Example</title>
... place text of right to left language here ...
Language(s): XHTML

See Also: