# Handle dir=rtl if needed

- Check 27.05 · Development and accessibility by language · Important
- Source: https://checklist-seo-geo.com/en/development-accessibility-language/handle-dirrtl-if-needed
- Serve Arabic, Hebrew or Persian with dir=rtl, CSS logical properties and mirrored icons on WordPress, Shopify, PrestaShop, Laravel or Next.js.
- Updated on 2026-11-25
- Licence: CC BY 4.0. Credit “Checklist SEO & GEO” with a link to https://checklist-seo-geo.com/en/development-accessibility-language/handle-dirrtl-if-needed.
- Plugin checklist-seo-geo: 1.3.1 · https://github.com/maximegaul/checklist-seo-geo

## In short

Arabic, Hebrew, Persian, Urdu and a few other languages are written from right to left (RTL). A version in one of these languages must declare this writing direction in the HTML, `<html lang="ar" dir="rtl">`, and its layout must flip: menu on the right, reversed arrows, mirrored margins. The task only concerns sites that publish at least one RTL language. Once it is done, the RTL version reads naturally, with no misplaced punctuation or overlapping elements.

## Why it matters

The `dir` attribute sets the base direction of the text. The browser then applies the Unicode bidirectional algorithm: Arabic letters run from right to left, embedded numbers and Latin words stay left to right, and punctuation is placed according to the base direction. Without `dir="rtl"`, an Arabic sentence that ends with a period or a Latin brand name is displayed out of order.

The W3C recommends declaring the direction in the markup rather than in CSS (`direction: rtl`): it is part of the meaning of the content, and must remain present when styles do not apply, for example in a feed reader, an extraction tool or the browser's reader mode.

The layout matters as much as the text. An Arabic-speaking visitor scans the page from right to left: they expect the logo and menu on the right, the “next” icon pointing left, carousels that move to the left. A site that is merely translated, with a left-to-right layout, feels foreign and is harder to understand.

On the search engine side, nothing indicates that Google uses `dir`: it detects the language from the content. What is at stake is the visitor experience, and therefore the engagement and conversion of the RTL version.

## What it improves

- **Readability**: text, punctuation, numbers and Latin words in the right place.
- **Experience**: a layout that matches reading habits, intuitive navigation.
- **Conversion**: forms, prices and call-to-action buttons laid out correctly on the RTL version.
- **Accessibility**: a consistent reading order for assistive technologies.
- **Rankings**: no documented direct effect.

## How to check

Read the `<html>` tag of an RTL page:

```bash
curl -s https://example.com/ar/ | grep -o -i -m 1 '<html[^>]*>'
```

Expected: `<html lang="ar" dir="rtl">`. Pages in the other languages must not carry `dir="rtl"`.

Find the physical CSS properties that will not flip:

```bash
grep -rnE '(margin|padding|border)-(left|right)|text-align:\s*(left|right)|float:\s*(left|right)|(^|[^-])(left|right):' resources/css src/styles --include='*.css' --include='*.scss' | wc -l
```

Each occurrence is a candidate for replacement with a logical property.

Visual check, on the homepage and on one page of each template:

- the menu, logo and breadcrumb start from the right;
- navigation, carousel and pagination arrows point the right way;
- non-directional icons (magnifying glass, cart, video play) are not mirrored;
- phone numbers, email addresses, references and prices remain readable;
- form fields are right-aligned, except email, phone and URL.

In the console, `getComputedStyle(document.documentElement).direction` must return `rtl` on the RTL version.

## How to implement

### Before you start

**Languages concerned.** The most common codes: `ar` (Arabic), `he` (Hebrew), `fa` (Persian), `ur` (Urdu), `ps` (Pashto), `sd` (Sindhi), `ug` (Uyghur), `yi` (Yiddish), `dv` (Dhivehi), `ckb` (Sorani Kurdish). Keep an explicit list in the configuration rather than guessing.

**The markup.**

- `dir="rtl"` on `<html>`, together with `lang`, for the whole page. Do not use it to right-align a block in a French page.
- `dir="auto"` on text areas filled in by visitors (comments, reviews, search field): the browser picks the direction from the first strong character.
- `<bdi>` around inserted text whose direction you do not know (user name, product name) so that it does not disrupt the sentence.
- `dir="ltr"` on fields that stay left to right in every language: `<input type="email" dir="ltr">`, phone, URL, code.
- An Arabic passage in a French page: `<span lang="ar" dir="rtl">`.

**What to flip, and what not to.**

| Element | In RTL |
|---|---|
| “Next” and “previous” arrows, menu chevrons | Mirrored |
| Progress bar, carousel, breadcrumb | Reversed direction |
| Video play icons, clock, logos | Not mirrored |
| Check marks, magnifying glass, cart | Not mirrored (unless the drawing is directional) |
| Charts with a time axis | To be decided; often kept left to right |
| Numbers | Left to right, digits following the country's convention |

Number and date formats are covered in [adapt date and number formats](https://checklist-seo-geo.com/en/editorial-keyword-localization/adapt-date-number-formats).

### Adapt the CSS

Replace physical properties with logical properties, which follow the text direction:

| Physical | Logical |
|---|---|
| `margin-left` / `margin-right` | `margin-inline-start` / `margin-inline-end` |
| `padding-left` / `padding-right` | `padding-inline-start` / `padding-inline-end` |
| `border-left` | `border-inline-start` |
| `left: 0` / `right: 0` | `inset-inline-start: 0` / `inset-inline-end: 0` |
| `text-align: left` | `text-align: start` |
| `float: left` | `float: inline-start` |
| `border-top-left-radius` | `border-start-start-radius` |

Flexbox and Grid already follow the direction: `justify-content: flex-start` starts from the right in RTL. For anything that genuinely has to change with the direction, target the attribute:

```css
.icon-next {
  display: inline-block;
}

[dir="rtl"] .icon-next {
  transform: scaleX(-1);
}

.card {
  padding-inline: 1rem 2rem;
  border-inline-start: 4px solid var(--accent);
  text-align: start;
}
```

Recent browsers also support the `:dir(rtl)` pseudo-class, which takes the inherited direction into account.

**Tailwind CSS** provides logical utilities (`ms-4`, `me-4`, `ps-4`, `pe-4`, `start-0`, `end-0`, `text-start`) and the `rtl:` and `ltr:` variants (`rtl:-scale-x-100` to mirror an icon). **Bootstrap 5** provides a dedicated stylesheet, `bootstrap.rtl.min.css`, to load instead of the standard stylesheet on RTL pages.

Arabic and Hebrew fonts often need a larger size and line height: see [check fonts for each language](https://checklist-seo-geo.com/en/development-accessibility-language/check-fonts-each-language).

### WordPress

Versions: WordPress 6.4 and later; Polylang 3, WPML 4 and 5.

WordPress adds `dir="rtl"` in `language_attributes()` when the site's locale is an RTL language (`is_rtl()`), in addition to `lang`. With Polylang or WPML, the direction of each language is defined in its settings (`Languages > Languages` for Polylang): check that it is set to right to left for Arabic.

The theme must provide its RTL stylesheet. By convention, WordPress loads `rtl.css` from the theme root on RTL pages. For a stylesheet registered with `wp_enqueue_style`, declare its variant:

```php
add_action('wp_enqueue_scripts', function (): void {
    wp_enqueue_style('my-theme', get_stylesheet_uri(), [], '1.0');

    wp_style_add_data('my-theme', 'rtl', 'replace');
});
```

With `replace`, WordPress loads `style-rtl.css` instead of `style.css` on RTL pages; the file must exist in the same folder. The CSS of core blocks already handles RTL. Also test the admin if writers work in Arabic.

### Shopify

Versions: Online Store 2.0 themes, all Shopify plans, November 2026.

Shopify exposes the page's language in `request.locale.iso_code`, but not its direction. Add the condition in `layout/theme.liquid`:

```liquid
{%- assign rtl_languages = 'ar,he,fa,ur' | split: ',' -%}
{%- assign language_code = request.locale.iso_code | split: '-' | first -%}
<html class="no-js" lang="{{ request.locale.iso_code }}"{% if rtl_languages contains language_code %} dir="rtl"{% endif %}>
```

RTL layout support then depends on the theme: some themes flip automatically, others do not. Check the theme's listing before opening an RTL language, and fix its CSS with logical properties in `assets/`.

### PrestaShop

Versions: PrestaShop 8 and 9.

For an installed RTL language, PrestaShop adds the `lang-rtl` class to `<body>` and loads the theme's RTL stylesheets: `rtl.css` as an override, or the `_rtl` variant of each stylesheet (`theme_rtl.css`). To generate them: `Design > Theme & Logo`, “Adaptation to Right-to-Left languages” section (visible only if an RTL language is installed), choose the theme and enable RTL stylesheet generation. Do not edit the generated files: put your fixes in a `.rtlfix` file with the same name (`theme.rtlfix` for `theme.css`), delete the existing `_rtl.css` files, which PrestaShop does not overwrite, then regenerate.

### Drupal

Versions: Drupal 10 and 11.

Each language has a direction setting (`Configuration > Regional and language > Languages`, edit the language, “Direction”). Drupal then writes `dir="rtl"` in `html.html.twig`. Core themes provide their RTL rules; a custom theme must use logical properties or `[dir="rtl"]` selectors.

### Laravel

Versions: Laravel 11 to 13.

Declare the RTL languages in `config/app.php`:

```php
'rtl_locales' => ['ar', 'he', 'fa', 'ur'],
```

Then in the layout template:

```blade
@php($locale = app()->getLocale())
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', $locale) }}" dir="{{ in_array($locale, config('app.rtl_locales'), true) ? 'rtl' : 'ltr' }}">
```

With Vite and Tailwind CSS, the `rtl:` variants are usually enough; with a separate stylesheet, load it under the same condition.

### Next.js

Versions: Next.js 15.5 and 16 (App Router).

In `app/[lang]/layout.tsx`, compute the direction from an explicit list:

```tsx
const rtlLocales = ['ar', 'he', 'fa', 'ur']

export default async function RootLayout({ children, params }: LayoutProps<'/[lang]'>) {
  const { lang } = await params
  const dir = rtlLocales.includes(lang.split('-')[0]) ? 'rtl' : 'ltr'

  return (
    <html lang={lang} dir={dir}>
      <body>{children}</body>
    </html>
  )
}
```

The value is then in the server-rendered HTML. Avoid setting it in a `useEffect`, which causes a visible flip after the page is displayed.

### Nuxt

Versions: Nuxt 3 and 4, @nuxtjs/i18n module 9 and 10.

With Nuxt i18n, add `dir: 'rtl'` to the locale declaration (`{ code: 'ar', language: 'ar', dir: 'rtl' }`); `useLocaleHead()` then returns `dir` in `htmlAttrs`, to be applied to `<html>` with `useHead` as for `lang`: see [set html lang on each page](https://checklist-seo-geo.com/en/development-accessibility-language/set-html-lang-each-page).

### Astro

Versions: Astro 5 to 7.

In the layout: `<html lang={Astro.currentLocale} dir={['ar', 'he', 'fa', 'ur'].includes(Astro.currentLocale ?? '') ? 'rtl' : 'ltr'}>`.

## Common mistakes

- **`direction: rtl` in CSS instead of `dir="rtl"`**: the direction disappears as soon as styles do not apply, and the W3C advises against it.
- **Layout not flipped**: Arabic text in a page whose menu, margins and arrows stay left to right.
- **Flipping everything**: logos, video play icons, screenshots and charts mirrored.
- **Email and phone fields in RTL**: confusing input, addresses displayed incorrectly.
- **Visitor content without `dir="auto"`**: an English review on the Arabic version, or the reverse, is displayed with punctuation in the wrong place.
- **Direction set in JavaScript**: the initial HTML stays `ltr`, and the page flips after loading.
- **CSS hard-coded with `left` and `right`** in third-party components: carousels, drop-down menus, cookie banners. Test them one by one.

## Frequently asked questions

### Should you write dir="rtl" or direction: rtl in CSS?

Use the dir="rtl" attribute in the HTML, on the html tag for a whole page or on the relevant element for a passage. The W3C advises against setting the base direction in CSS, because it is part of the meaning of the content and must remain present when styles do not apply. CSS then serves to adapt the layout, preferably with logical properties such as margin-inline-start.

### Does the dir attribute have an effect on SEO?

No documented effect. Google determines the language of a page from its visible content, and its documentation does not mention the dir attribute. Its value lies in the visitor experience: a correctly oriented Arabic or Hebrew version reads naturally, which helps engagement and conversion. Language targeting relies on the content, separate URLs and hreflang annotations.

### Which icons should be mirrored in RTL mode?

Mirror icons that express a reading or progress direction: next and previous arrows, menu chevrons, back, pagination, progress bar. Do not flip non-directional icons or real-world objects: magnifying glass, cart, clock, video play button, logos. In CSS, a [dir="rtl"] rule with transform: scaleX(-1) on the directional icons only is enough, or Tailwind CSS's rtl: variant.

### How do you handle English text in an Arabic page?

The browser largely takes care of it thanks to the Unicode bidirectional algorithm: Latin words stay left to right within the Arabic sentence. Add lang="en" to the passage for pronunciation, and wrap inserted text whose language you do not know, such as a product name or a username, in bdi. For content entered by visitors, the dir="auto" attribute picks the direction based on the text.

## Resources

- [W3C: Structural markup and right-to-left text in HTML](https://www.w3.org/International/questions/qa-html-dir)
- [MDN: dir attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/dir)
- [MDN: bdi element](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/bdi)
- [MDN: CSS logical properties and values](https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Logical_properties_and_values)
- [MDN: :dir() pseudo-class](https://developer.mozilla.org/en-US/docs/Web/CSS/:dir)
- [Material Design: Bidirectionality](https://m2.material.io/design/usability/bidirectionality.html)
- [Bootstrap: RTL](https://getbootstrap.com/docs/5.3/getting-started/rtl/)
- [PrestaShop: RTL support in themes](https://devdocs.prestashop-project.org/9/themes/concepts/rtl/)

Next steps: [Check fonts for each language](https://checklist-seo-geo.com/en/development-accessibility-language/check-fonts-each-language) and [Test for text overflow](https://checklist-seo-geo.com/en/development-accessibility-language/test-text-overflow).
