How to: Display Right-to-Left Text Using HTML Tags for Globalization

When writing ASP.NET Web pages, the best way to make text flow from right to left is to use the dir (direction) attribute. The dir attribute is usually placed in either the html or body tag, and then controls and HTML elements on the page inherit from the specified direction.

The tag to which the dir attribute is applied affects how the page appears, as follows:

  • When the value for the dir attribute is rtl (right to left) in the html tag, the page gets the correct extended styles set. On a bidirectional-enabled system, the page displays as a right-to-left page and a vertical scrollbar appears on the left side.

  • When the value for the dir attribute is rtl (right to left) in the body tag, frames and captions do not inherit the right-to-left direction.

There are other ways to set the flow of text, including the bdo tag for bidirectional override, Unicode characters that have embedded directional information, cascading style sheets, and so on. For more information, go to the Global Development Computing Portal on Microsoft.com and search for information about authoring HTML for middle-eastern content.

To set the dir attribute in an ASP.NET Web page

  1. In the <html> or <body> tag, set dir to ltr or rtl.

    Security noteSecurity Note:

    This example has a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview.

    For example:

    <html dir="rtl">
    <!-- Or -->
    <body dir="rtl" >
    
  2. To override the default direction for individual controls, set dir for each control to ltr or rtl.

    For example:

    <table dir="ltr" >
    <asp:TextBox dir="ltr" >
    

See Also

Other Resources

ASP.NET Globalization and Localization