Skip to content

RTL support in Tailwind CSS: getting started

Set up RTL support in Tailwind CSS, migrate a first component to logical utilities, and verify direction and generated styles before rollout.

By , Founder of Ritla

Guide14 min read

There is no Tailwind configuration switch that turns an English interface into an Arabic one. Setting dir="rtl" changes the browser's layout direction, but a utility such as ml-auto still means a physical left margin. A trailing action can end up beside its label even though the row itself has started from the right.

The setup path is small: establish direction in HTML, prove that the intended utilities are generated, migrate one representative component, then carry it into the actual Arabic route. Keep rtl: for behavior that needs a direction-specific choice rather than adding it to every class.

This guide follows that path through a community-kitchen volunteer scheduler. Its first migrated component is a shift summary with an action at the reading end. The examples use Tailwind v4, with notes for an existing v3 project. The aim is a working first implementation and a repeatable way to extend it, rather than a catalog of every directional utility.

Check the project before installing an RTL plugin#

Find the installed Tailwind version, the stylesheet entry and the tool that compiles it. Use the lockfile or package manager output rather than guessing from the component syntax. Also check whether the project already has an RTL stylesheet transform, a direction provider or a component library with its own direction setting.

Modern Tailwind supplies logical utilities and rtl:/ltr: variants without an additional RTL plugin. Core logical utilities arrived in Tailwind v3.3. A project on v3.3 or v3.4 can begin adopting them without making a v4 migration part of the same change.

Choose the path that matches the installation:

Project stateFirst action
Tailwind v4 already builds the appKeep that integration and add a direction fixture
Tailwind v3.3 or v3.4Keep the v3 pipeline and check its content paths
Earlier Tailwind versionCheck utility availability and plan a supported upgrade separately
Existing RTL transformation or pluginInspect its generated declarations before introducing another mechanism
Tailwind not installedSet up the normal integration, then verify direction

Do not run a major-version upgrade just because a setup tutorial uses the newer import syntax. The v4 upgrade guide covers changes to integration, utilities and browser requirements. Those changes deserve their own validation.

Likewise, do not remove an existing plugin before checking what it does. It may supply application-specific utilities that the new logical classes do not replace. Start by understanding which layer owns direction and which layer owns each style. Two mechanisms that both modify an edge can produce a different result from either one alone.

Put direction at the document boundary#

For the Arabic scheduler, the document should begin with:

html
<html lang="ar" dir="rtl">

Language and direction are separate declarations. An Arabic language attribute does not make the layout RTL. text-right only aligns text; it does not declare the document's base direction. The W3C guidance on document direction recommends setting dir on html for an RTL document.

In a server-rendered application, produce the attributes from the resolved route locale in the template or root layout. Inspect the direct response for an Arabic deep link. A client effect that eventually changes the attributes is not evidence that the initial document was correct.

Give that decision one owner. If the route selects Arabic, but a separate browser preference later selects English, the page can contain Arabic labels with a direction chosen by a different rule. Pass the resolved locale and direction to components that require them rather than making each component infer its own page locale.

Use a wrapper-level dir for a component preview or a deliberately different-direction region. Do not add dir="rtl" to every button. Inheritance should do ordinary work, and scattered attributes make the later English view harder to reason about.

After setting the document attributes, reload both language routes. Check the root element and the actual shift component's computed direction. If the root is RTL but the component is LTR, inspect intermediate wrappers and library defaults before changing spacing classes.

Inspect attributes and computed styles as two separate pieces of evidence. A custom direction: rtl rule can make a wrapper look right-to-left while the HTML still declares something else. Conversely, an explicit CSS rule can override inherited layout direction beneath a correct document root. Resolve that disagreement at its source. A direction-sensitive component should not need one setting for its logical spacing and a contradictory setting for its variants.

R001 covers document direction missing, contradicted, or declared only in CSS. When that foundation is wrong, repairing individual margins merely hides part of the problem.

Build a small fixture with the real compiler#

Use an existing development route or component preview if the app already has one. It should load the same Tailwind stylesheet and theme as the product. A playground using a different Tailwind version is useful for experiments, but cannot establish that your project generates the same rules.

For a standalone v4 check, create src and public directories in a small scratch project with a package.json. Install the CLI dependencies there:

npm install -D tailwindcss @tailwindcss/cli

Create the stylesheet entry:

css
/* src/rtl-check.css */@import "tailwindcss" source(none);@source "../public/rtl-check.html";

The source path is relative to this stylesheet. Automatic detection is disabled for this scratch check so another file cannot accidentally supply classes missing from the fixture's source boundary. Tailwind's CLI setup explains the compile-and-link workflow; its source-detection documentation explains source registration. Do not copy that restricted source list into the application's main stylesheet: it would leave the rest of the app outside this entry's detection.

In an existing app, use its normal Vite, PostCSS or framework integration instead of adding the CLI as a second pipeline. The important property is that the fixture exercises the actual compiler and theme you intend to ship.

For v3, retain the existing Tailwind stylesheet directives and include the fixture in the configured content paths. Do not paste the v4 import into a v3 entry point. The v3 content configuration reference describes that setup.

Before judging RTL, verify that an ordinary style such as the fixture's padding appears. If the whole card is unstyled, inspect the stylesheet URL and build output. Direction cannot compensate for a stylesheet that was never loaded.

Migrate one trailing action to a logical margin#

The shift summary has its description first and an action at the far end of the row. In the English component, the action uses:

html
<button type="button" class="ml-auto shrink-0 rounded-md border border-slate-400 px-4 py-2">  عرض المناوبة</button>

On a normal LTR flex row, that automatic left margin can consume spare space before the button. After the row becomes RTL, the physical left margin is no longer the margin before the button in reading order. The button's placement no longer expresses the intended trailing-action relationship.

Use ms-auto, which sets the margin on the inline-start side. Tailwind documents this mapping in its margin reference. The browser resolves that side through the element's direction, so the same utility expresses the relationship in both modes.

Save this complete corrected fixture as public/rtl-check.html:

html
<!doctype html><html lang="ar" dir="rtl">  <head>    <meta charset="utf-8">    <meta name="viewport" content="width=device-width, initial-scale=1">    <title>مناوبات المطبخ المجتمعي</title>    <link rel="stylesheet" href="./rtl-check.css">  </head>  <body class="p-6">    <main class="mx-auto max-w-3xl">      <h1 class="mb-6 text-2xl font-semibold">مناوبات المطبخ المجتمعي</h1>      <section id="shift-card" class="flex items-center gap-4 rounded-lg border border-slate-300 p-5">        <div>          <h2 class="font-semibold">تحضير وجبات المساء</h2>          <p class="mt-2">مركز الحي الشرقي</p>        </div>        <button id="shift-action" type="button"                class="ms-auto shrink-0 rounded-md border border-slate-400 px-4 py-2">          عرض المناوبة        </button>      </section>    </main>  </body></html>

This is a layout fixture; the button does not open a shift until you wire it into the application. To reproduce the spacing failure, change only its ms-auto back to ml-auto, rebuild and compare at a width with spare row space.

Compile the stylesheet from the scratch project's root:

npx @tailwindcss/cli -i ./src/rtl-check.css -o ./public/rtl-check.css

Open the HTML through a local static server, or open the local file for this static layout check. Inspect the loaded stylesheet if no styling appears. Rebuild after changing a utility; changing the HTML dir attribute alone should not require generating a separate RTL stylesheet.

Under LTR, the replacement still uses the left margin, preserving the original English relationship. Under RTL, it uses the right margin. Do not retain both ml-auto and ms-auto: in RTL they can create automatic margins on both sides instead of the intended single starting margin.

This example depends on available row space. Auto margins do not create room in an already overfull container. Check a comfortable desktop width first so a content-width problem does not obscure the directional one.

Prove the relationship before translating the rest#

Change the fixture's dir between ltr and rtl while keeping its width fixed. For this isolated comparison, leaving the Arabic strings in place helps separate layout changes from text-width changes. Then create the real English fixture with translated content and matching language attributes.

Check that the description remains the first item in reading order and the action occupies the trailing edge. A normal flex row follows direction already. Do not add flex-row-reverse to repair the root direction or the automatic margin. MDN explains how flex direction depends on dir.

Use geometry as supporting evidence when the difference is hard to see. Run this in the browser console on the fixture:

js
const card = document.querySelector('#shift-card');const action = document.querySelector('#shift-action');if (!card || !action) throw new Error('Open the shift fixture first.');const direction = getComputedStyle(card).direction;const cardBox = card.getBoundingClientRect();const actionBox = action.getBoundingClientRect();console.table({  direction,  distanceFromTrailingEdge: direction === 'rtl'    ? actionBox.left - cardBox.left    : cardBox.right - actionBox.right,});

getBoundingClientRect() reports element geometry relative to the viewport. Here the subtraction compares two elements in that same coordinate system. The remaining distance should reflect the card's border and padding when the action sits at its inner trailing edge. Do not expect zero or hard-code a theme-independent pixel value.

Repeat the comparison with the broken margin. If the row has no spare space, increase the fixture width before interpreting the result. A measurement without its layout conditions can lead to the wrong diagnosis.

Also Tab to the action and activate its real implementation after integration. Its visual location, focus appearance and resulting behavior are separate acceptance checks. A static fixture proves the spacing rule, not the completed user journey.

Establish a small utility policy for new components#

Start with the relationships the team uses repeatedly. Indentation before a label becomes ms-*; space after it becomes me-*. Use ps-* and pe-* for corresponding padding, and text-start or text-end when alignment follows the text element's direction.

Teach the underlying distinction once: these are logical CSS properties, not Arabic-specific alternatives. MDN's logical-property guide connects inline edges to direction and writing mode. For a broader migration, use CSS logical properties for RTL.

Write the review rule around intent rather than banning class names. A physical coordinate on the kitchen's floor-plan image should remain physical. A control placed before the shift description in reading order should adapt. A reviewer should be able to explain which of those relationships a utility represents.

Remove the replaced utility instead of appending a logical one. pl-4 and ps-4 can affect different sides in RTL. Moving a class to the end of the attribute does not make it cancel another property.

Audit responsive prefixes at the same time. A component can use logical base spacing while lg:ml-8 reintroduces the English edge on a larger screen. Search shared component defaults as well as the page that consumes them; a caller's logical class does not automatically erase a physical class inside the component.

Keep the policy small enough to apply in the first change. Convert the shift summary and its shared button wrapper, verify them, then repeat for the next component. A repository-wide replacement makes it harder to distinguish intentional physical coordinates from accidental English assumptions.

R030 covers direction-sensitive physical properties without an RTL override. Use a finding to inspect the intended relationship, not as an instruction to replace every physical property with the same logical side.

Introduce rtl variants for an actual exception#

The shift summary needed a logical margin, not two locale-specific branches. A popover animation may need a different choice: its scale origin can belong at the top of the reading-start edge.

First verify variant selection independently from the animation. Temporarily add this diagnostic line inside the fixture's body and rebuild:

html
<p class="hidden rtl:block">تم تفعيل اتجاه العرض العربي</p>

Check that it appears in the RTL fixture and disappears when the document is LTR. Remove it after the check. If ordinary styles work but this line never appears, inspect whether the variant rule was generated. If it stays visible in both modes, inspect the actual direction attributes and matching selectors. This separates a selector problem from a motion problem before transforms complicate the evidence.

For that behavior, origin-top-left rtl:origin-top-right keeps the English origin and changes the Arabic origin. Tailwind's transform-origin reference describes the physical corners. Apply the rule to the surface being scaled, not to unrelated text or an entire application shell.

Horizontal translation is also physical. If a particular notification is designed to offset toward opposite sides in the two modes, ltr:translate-x-3 rtl:-translate-x-3 expresses those opposing x-offsets. Tailwind's translation utilities do not infer the intended direction of travel from an Arabic label.

Test where the element begins, how it moves and where it finishes. Reversing a sign is useful only if the interaction is meant to reverse. Do not mirror a floor-plan coordinate, a logo or every SVG as part of the initial setup. R033 covers translateX moving an element off-screen in RTL. Inspect the generated CSS and test current Tailwind translation utilities directly as well; other motion decisions require their own interaction review.

Check the generated selector when a component can appear inside a nested LTR region. The current direction-variant reference includes ancestor matching, so an RTL ancestor can make rtl: apply inside a locally LTR panel. It is not safe to assume the variant always represents the nearest direction boundary.

For a rule that must use the element's own HTML directionality, an arbitrary variant such as [&:dir(rtl)]:origin-top-right is an option. MDN documents :dir(), including its distinction from CSS-only direction. Inspect support in the project's browser policy and test the nested boundary rather than substituting selectors without verification.

Bring the fixture into the actual Arabic route#

Once the isolated component behaves correctly, render it with the production theme, font, shared layout and translations. This step finds assumptions that the fixture intentionally excluded.

Open the Arabic schedule directly, then reach it through the app's language switcher. Refresh it. Compare the document's attributes and the shift action's position after each journey. A component preview with dir="rtl" does not prove that the application route supplies that direction.

Open the shift-details popover or dialog. If it is portaled outside the component wrapper, inspect its own inherited direction and its library configuration. The wrapper in a preview does not become an ancestor of content rendered elsewhere in the document. Declaring direction on html covers the document foundation, while a library can still introduce an explicit override.

Keep technical text boundaries local. An English kitchen-equipment note can have its own language and direction without making the Arabic shift card LTR. A reference identifier embedded in Arabic text may need isolation even when every margin is correct. Use bidi isolation for that problem rather than forcing an entire card to LTR.

Enter realistic Arabic review text and inspect the actual font rendering. A layout utility cannot supply missing Arabic font coverage, translate a dialog label or choose the direction of an identifier. Treat those as explicit follow-up checks on the same route instead of claiming that the Tailwind setup completed all Arabic QA.

If the standalone fixture passes and the application fails, preserve that evidence. Compare the stylesheet rules, active theme, intermediate wrappers and final class list. Do not rewrite the working fixture until you have identified what the application adds.

Add responsive states after the first direction check#

The initial summary is a row so the automatic-margin behavior is visible. At a narrow width, a translated shift title and an action may need a stacked layout. Change the section's class list to use flex flex-col items-start gap-4 sm:flex-row sm:items-center, retaining its border, padding and radius utilities.

Change the action's ms-auto to sm:ms-auto at the same time. Below that breakpoint, the button can follow the stacked content at the starting edge. At the row breakpoint, its logical automatic margin resumes the trailing-action relationship. The base automatic margin is no longer appropriate just because it worked in the desktop row.

Use the project's configured breakpoint rather than assuming a copied sm: value matches its design. Inspect both directions immediately below and above the transition. Include a long shift name and an unavailable or disabled action so the test covers more than the shortest successful state.

Where labels can wrap, prefer a real flex or grid gap over adding side margins to every child. If a shared component already uses space-x-*, inspect its generated CSS before adding a reversal workaround. The v3 and v4 implementations differ; the upgrade guide documents spacing-selector changes.

Do not hide overflow as a first repair. It can remove the visible symptom while also hiding a button, a focus ring or the end of a shift description. Determine which element exceeds its available space, then choose wrapping, shrinking, stacking or deliberate truncation according to the task. Arabic text overflow covers that investigation.

Verify the production stylesheet before extending rollout#

Build the application with its normal production command and inspect the deployed Arabic schedule. A utility present during development can be absent from another bundle or a fixture with different source registration.

Keep complete utility names in source. A class assembled from fragments such as a margin prefix plus a locale-selected letter may not be discovered by Tailwind's scanner. For spacing that follows direction, use a literal logical utility. For a genuine conditional choice, use complete literal class strings and ensure that their file is included in generation.

If a shared package owns the component, check whether its files are scanned by the consuming app. In v4, register necessary external source paths; in v3, check content paths. Prefer correcting the source boundary to adding unrelated sample classes elsewhere merely to make them appear in the output.

When something fails, locate the first broken layer:

EvidenceNext inspection
Card has no Tailwind stylingStylesheet loading and compilation
Ordinary styles work, logical rule is absentInstalled version, literal class and source detection
Logical rule exists but losesCompeting declarations, layers and specificity
Root is RTL, card computes LTRIntermediate direction overrides
Fixture passes, popover failsPortal ancestry and library direction settings
Both directions fail only on narrow screensAvailable space and responsive layout

Record the route, viewport, direction, relevant class list and computed declaration when filing the defect. That is enough to reproduce a spacing failure without treating every Arabic screenshot as the same bug.

Before migrating another screen, require the initial shift summary to pass in the existing English view, the Arabic direct-load view, the language-switch journey and the narrow layout. Keep the fixture as a small regression example for future changes to shared spacing or build configuration.

Decide what counts as a regression before approving the first screenshots. In the English view, compare the action's trailing alignment, surrounding spacing and focus appearance with the existing component. In Arabic, verify the same relationships from the opposite reading start. A changed position alone is not a failure when the layout is expected to adapt, and a pixel-identical screenshot is not a success if the action should have moved. Tie the evidence to the component's purpose.

A free Ritla scan of the first Arabic route can surface missing or contradictory document direction and direction-sensitive physical properties without RTL overrides. Use debugging RTL layout problems when the fixture and application disagree, then convert the remaining LTR CSS component by component once the setup is proven.

Checks in this guide

See what your Arabic pages are hiding

Paste a URL. Ritla renders the page on desktop and mobile, runs every check, and shows the top issues with screenshot evidence.

Scan a page freeBrowse the checks