Skip to content
TheChatArchiveThe Chat Archive
grok-3-preview-02-24· xAIHugging Face LMArena Human Preference 140K

If you have a list of Arabic and English sentences in html, how can we make the English…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Geminigemini-2.5-pro-preview-05-06’s answer.
  1. User

    If you have a list of Arabic and English sentences in html, how can we make the English have LTR direction while the Arabic items have RTL direction in the same list ?

  2. Assistant

    To create a list (<ul>) in HTML where English sentences are displayed with left-to-right (LTR) direction and Arabic sentences are displayed with right-to-left (RTL) direction, you can use the dir attribute or CSS to control the text direction for each list item (<li>). Below are two approaches to achieve this:

    Approach 1: Using the dir Attribute

    The dir attribute is an HTML attribute that specifies the text direction of an element. You can set it to ltr for English and rtl for Arabic.

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Bi-Directional List</title>
    </head>
    <body>
        <ul>
            <li dir="ltr">This is an English sentence.</li>
            <li dir="rtl">هذه جملة عربية.</li>
            <li dir="ltr">Another English sentence.</li>
            <li dir="rtl">جملة عربية أخرى.</li>
        </ul>
    </body>
    </html>
    

    Approach 2: Using CSS

    You can use CSS to control the text direction by applying the direction property. This approach is useful if you want to separate styling from content or apply the direction to multiple elements at once using classes.

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Bi-Directional List</title>
        <style>
            .ltr {
                direction: ltr;
                text-align: left;
            }
            .rtl {
                direction: rtl;
                text-align: right;
            }
        </style>
    </head>
    <body>
        <ul>
            <li class="ltr">This is an English sentence.</li>
            <li class="rtl">هذه جملة عربية.</li>
            <li class="ltr">Another English sentence.</li>
            <li class="rtl">جملة عربية أخرى.</li>
        </ul>
    </body>
    </html>
    

    Key Points:

    1. dir Attribute:

      • Use dir="ltr" for left-to-right text (English).
      • Use dir="rtl" for right-to-left text (Arabic).
      • This is a semantic approach and is recommended for accessibility.
    2. CSS direction Property:

      • Use direction: ltr; for English.
      • Use direction: rtl; for Arabic.
      • Combine with text-align to ensure proper alignment of text within the list items.
    3. Accessibility:

      • Using the dir attribute is better for accessibility and screen readers, as it provides semantic information about the text direction.
      • If you use CSS, consider adding the dir attribute as well for better accessibility.
    4. Unicode and Fonts:

      • Ensure your HTML document uses UTF-8 encoding (<meta charset="UTF-8">) to properly display Arabic characters.
      • Use a font that supports both Arabic and English characters for consistent rendering.
    5. List Styling:

      • If you want to adjust the alignment of list markers (bullets), you may need additional CSS, such as list-style-position or padding adjustments, to ensure the markers align correctly with the text direction.

    Example with Enhanced Styling

    If you want to ensure the list markers (bullets) also respect the text direction, you can use the following enhanced CSS:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Bi-Directional List</title>
        <style>
            ul {
                list-style-position: outside;
            }
            .ltr {
                direction: ltr;
                text-align: left;
            }
            .rtl {
                direction: rtl;
                text-align: right;
            }
        </style>
    </head>
    <body>
        <ul>
            <li class="ltr" dir="ltr">This is an English sentence.</li>
            <li class="rtl" dir="rtl">هذه جملة عربية.</li>
            <li class="ltr" dir="ltr">Another English sentence.</li>
            <li class="rtl" dir="rtl">جملة عربية أخرى.</li>
        </ul>
    </body>
    </html>
    

    Output:

    • English sentences will be aligned to the left with LTR direction.
    • Arabic sentences will be aligned to the right with RTL direction.
    • List markers (bullets) will appear on the correct side of each list item based on the text direction.

    This approach ensures proper rendering of mixed-language content while maintaining accessibility and usability.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.

If you have a list of Arabic and English sentences in… · The Chat Archive