Skip to content

Tailwind RTL: the complete guide

Build Arabic Tailwind layouts with logical utilities, direction variants and responsive fixes, then test the generated CSS in both directions.

By , Founder of Ritla

Guide14 min read

A Tailwind component can move its first flex item to the right when the page becomes Arabic while leaving its indentation, accent border and floating status label on the left. That is not a partial failure of Tailwind. The browser is following direction for layout and following physical instructions for the remaining properties.

Build around that distinction. Use logical utilities for edges that mean the beginning or end of a component. Use rtl: and ltr: for direction-dependent behavior that has no suitable logical property. Keep physical coordinates when they describe something genuinely fixed, such as a position on a scanned manuscript.

This guide uses a manuscript-digitization queue to show the differences. It covers current Tailwind v4 syntax and calls out relevant v3 behavior. A utility's generated CSS is the final authority, especially when upgrading an existing project or combining Tailwind with a component library.

Declare direction in HTML, not in Tailwind configuration#

An Arabic page needs a document direction as well as a language:

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

Neither translating labels nor adding text-right declares right-to-left direction. text-right controls alignment; it does not establish how a flex row starts or give mixed text an RTL paragraph base. The W3C direction guidance recommends declaring the overall direction on html.

For a component preview, put dir on the preview wrapper. For the actual Arabic route, declare it on the document. Test English with dir="ltr" as well. A component should inherit direction unless it has a reason to establish a different one.

Tailwind's built-in logical utilities and direction variants do not require an RTL plugin or an rtl: true configuration option. In a v4 project already connected to its build tool, the stylesheet entry remains:

css
@import "tailwindcss";

Follow the installation instructions for your integration if Tailwind is not installed. Direction handling does not replace that setup, and adding a second processing plugin to an established pipeline is not an RTL fix.

Tailwind added its core inline logical utilities in v3.3. On an older installation, check the version before debugging a class that the compiler does not recognize. A v3 application also needs its normal content-file configuration; copying a v4 stylesheet entry into it is a separate migration.

The positioning examples below use inset-s-* and inset-e-*, as in the current v4 documentation. In v3.3 and v3.4, the corresponding names are start-* and end-*. Keep documentation and installed versions aligned.

Translate physical intent into logical utilities#

In ordinary horizontal Arabic layout, inline start is the right edge and inline end is the left edge. For English, those edges are reversed. Logical properties map through direction and writing mode, as MDN explains.

Use this table when an existing English component's edge is meant to follow reading direction:

Existing English utilityLogical replacementMeaning
ml-4ms-4Margin at inline start
mr-4me-4Margin at inline end
pl-6ps-6Padding at inline start
pr-6pe-6Padding at inline end
text-lefttext-startAlign text to its own starting edge
text-righttext-endAlign text to its own ending edge
left-3inset-s-3Position against inline start
right-3inset-e-3Position against inline end
border-l-2border-s-2Border on the starting side
border-r-2border-e-2Border on the ending side
rounded-l-lgrounded-s-lgRound the starting pair of corners
rounded-r-lgrounded-e-lgRound the ending pair of corners

The replacements preserve the English side under dir="ltr". Do not convert right-3 to inline start merely because the Arabic design needs something on the right. That changes the English component too. First name the relationship, then choose the edge.

Tailwind documents logical padding, insets, alignment, borders and corner radii separately. Keep those mappings handy instead of building a second utility naming system in application code.

This is not a search-and-replace instruction for every left or right value. A manuscript annotation measured from the image's physical left edge should remain attached to that coordinate when the surrounding controls become Arabic. Mirroring the coordinate would point at a different word on the scan.

Alignment follows the direction of the element carrying the text, not an abstract page-wide preference. An English log with dir="ltr" and text-start starts on the left even inside the Arabic queue. If the log's box belongs at the queue's trailing edge, position that box through its parent layout. Changing the log's text alignment to move the box confuses two separate decisions. The CSS text-alignment reference explains how start and end resolve.

Fix a queue notice without changing its English layout#

Suppose a digitization notice needs an accent border at the reading start, extra indentation after that border, and a trailing status. The original classes encode the English edges:

Problem

html
<article class="border-l-4 border-amber-500 pl-5 text-left">  <h2 class="font-semibold">مراجعة دفعة المخطوطات</h2>  <p>تحتاج الصور الجديدة إلى مراجعة قبل النشر.</p>  <p class="mt-3 text-right">بانتظار التدقيق</p></article>

Under RTL, border-l-4 still selects the physical left border, pl-5 still adds left padding, and text-left still aligns to the left. The markup supplies no instruction to move those edges. Declaring document direction does not rewrite physical CSS.

Better

html
<article class="border-s-4 border-amber-500 ps-5 text-start">  <h2 class="font-semibold">مراجعة دفعة المخطوطات</h2>  <p>تحتاج الصور الجديدة إلى مراجعة قبل النشر.</p>  <p class="mt-3 text-end">بانتظار التدقيق</p></article>

Only the direction-sensitive classes changed. In English, start still maps to the left and end to the right. In Arabic, the notice's border and indentation follow its starting edge, while the status aligns to its ending edge.

Verify both modes with the same component width. Inspect the computed border widths and padding, then compare screenshots. Translate the content for the real English fixture; keeping Arabic text while changing the wrapper direction is useful for isolating layout behavior, but does not represent the finished English product.

Do not leave the original physical utilities alongside their replacements. A list containing both pl-5 and ps-5 can assign padding to both sides in RTL. The new utility does not cancel a different physical property.

R030 covers direction-sensitive physical properties without an RTL override. R022 covers explicit left alignment on majority-Arabic text. Neither finding means every physical property must be removed; the component's intended relationship still matters.

Use direction variants where the behavior needs a decision#

A logical property expresses one relationship in both directions. A variant selects a different rule. Prefer the former for ordinary spacing: ms-4 is clearer than independently maintaining ltr:ml-4 and rtl:mr-4.

Use a variant when the change is genuinely conditional, such as reversing a directional icon. This queue action advances to the next review item:

html
<button type="button" class="inline-flex items-center gap-2">  <span>المخطوطة التالية</span>  <svg aria-hidden="true" viewBox="0 0 24 24"       class="size-4 rtl:rotate-180" fill="none" stroke="currentColor">    <path d="M5 12h14m-6-6 6 6-6 6" />  </svg></button>

The SVG drawing points right before rotation. The class changes that drawing in the RTL case; direction alone does not redraw its path. Confirm that the queue's actual advance direction agrees with the icon, rather than deciding from the Arabic label alone. R025 concerns an icon pointing against the sequence its control advances.

Do not rotate a complete button, its label or a scanned image. Likewise, a download symbol or a manuscript seal does not become directional simply because it sits in an Arabic toolbar. See what should be mirrored in RTL for that decision.

When retaining physical properties, replace the complete side relationship. For example, moving a positioned item from right-3 to the other side with rtl:left-3 can leave both physical insets active. Reset the old side with rtl:right-auto, or use a single logical inset when the intended relationship permits it.

Check nested LTR regions against the generated selector#

An English operator-log panel inside the Arabic queue is a useful boundary test. Logical padding follows that panel's local direction, but a direction variant may match because of an ancestor.

The current Tailwind variant reference includes this selector branch for rtl::

css
[dir="rtl"] *

That branch still matches descendants inside a nested dir="ltr" panel. Do not assume rtl: means “the nearest direction is RTL.” Inspect the selector emitted by your installed version. With direction attributes in both modes, an element can match the ancestor branches of both rtl: and ltr:.

For a rule that must follow the element's own semantic direction, use an arbitrary variant such as [&:dir(rtl)]:rotate-180. MDN's :dir() reference explains that it respects inherited HTML directionality, while excluding direction set only through CSS.

Test this boundary explicitly after an upgrade. It is a reason to inspect variant semantics, not a reason to wrap every component in a new direction attribute.

Let flex and grid handle direction before reversing order#

A normal flex row already uses the inline direction. On an RTL page, its first item starts on the right. Adding rtl:flex-row-reverse to “enable RTL” reverses that relationship again.

For the queue's review actions, keep the intended reading sequence in the markup:

html
<div class="flex flex-wrap items-center gap-3">  <button type="button">قبول الصور</button>  <button type="button">طلب إعادة التصوير</button>  <button type="button">تأجيل المراجعة</button></div>

Check the first action in each direction, then Tab through the buttons. A layout that looks reversed correctly can still expose a surprising focus sequence when order-*, row reversal or positive tabindex values have been added.

MDN documents how flex direction interacts with dir. Use reversal only when the product truly needs the opposite sequence within the current direction. R081 covers row-reverse used to fake RTL instead of declaring direction.

Auto-placement in a simple grid also follows direction. Do not reverse the source array just because the first tile appears on the right. Explicit placement, dense packing and custom ordering need their own review; an automatically placed gallery and a fixed manuscript-coordinate grid do not have the same contract. The RTL grid guide covers placement in more depth.

For a trailing action within a flex row, ms-auto can consume available space on the logical starting side of that action. This needs spare space in the row. It will not solve a row whose children already exceed the container, and its behavior needs reconsideration if the layout changes to a column.

Do not assume every utility containing “start” describes the same axis. text-start aligns inline text, while items-start controls alignment on a flex container's cross axis. In a normal horizontal flex row, that cross axis is vertical; in a column it is horizontal. The align-items utilities therefore need to be read alongside flex-row or flex-col. A responsive axis change can explain an alignment failure that adding rtl: would only obscure. Inspect the active flex direction at the failing width before changing the alignment class.

Prefer gap for groups that can wrap#

gap-3 creates separation between flex or grid items without choosing a left or right margin for individual children. It is a good fit for the wrapping review-action group. Tailwind's gap utilities express that directly.

Do not copy rtl:space-x-reverse into every row. In v3, horizontal space utilities use physical child margins, so RTL layouts can need reversal. Current v4 utilities use logical margins and a different child selector. The v3 space documentation, current margin reference and upgrade guide describe the relevant implementations.

For a normal v4 row, adding a reversal solely because the document is RTL can put spacing on the wrong child edge. Inspect the generated CSS before preserving an old workaround. Also inspect hidden children and any extra child margins after migration.

Neither version's margin-based spacing shortcut is a substitute for a wrapping layout's gap. Remove the old space utility when switching to gap; using both can introduce a second source of spacing. Check the last item on each wrapped line, where an inappropriate child margin becomes easier to see.

Anchor labels and overlays to the intended edge#

A floating inspection badge on a manuscript preview may belong at inline end. An existing English right-3 implementation should then become inset-e-3, not inset-s-3.

html
<div class="relative min-h-36 border border-slate-300">  <span class="absolute inset-e-3 top-3 rounded px-2 py-1">    فحص الجودة  </span></div>

The relative preview is the containing block. The badge stays on the right in LTR and moves to the left in RTL. This changes the interface decoration, not the pixels or annotation coordinates of the manuscript image beneath it. For more positioning cases, use absolute positioning in RTL layouts.

A menu anchored to a queue control needs more than a logical inset. Open it near each viewport edge, at the narrowest supported width and with the longest translated option. Verify its actual containing block and collision handling. A menu library may calculate placement itself, so adding an opposing Tailwind inset can conflict with its positioning logic.

Inspect portaled content separately. A menu rendered under body does not inherit from a local queue-preview wrapper that lives elsewhere in the DOM. With direction on the document, it can inherit that direction; with direction only on a component preview, configure the portal's direction through the library's supported mechanism or wrapper.

Borders and corner radii should follow the same relationship as the attached edge. A notice with border-s-4 but rounded-l-lg can move its accent while retaining English corner styling. Use rounded-s-lg only when that pair of corners belongs to the starting edge. Symmetric rounded-lg needs no directional counterpart.

Test the menu open, not just the trigger. A screenshot of a closed toolbar provides no evidence about the menu's alignment, width or focus behavior.

Keep transforms physical until the design says otherwise#

Logical positioning does not turn horizontal translation into logical movement. translate-x-2 still moves along the physical x-axis. Tailwind's translation utilities and the CSS translate definition describe that coordinate system.

For a decorative advance motion, a pair such as ltr:translate-x-2 rtl:-translate-x-2 can express opposite physical offsets. Check the nested-direction caveat above if the control can appear in a locally LTR region.

Do not flip every animation. A pointer following a measured location on a manuscript, a physical drag offset and a reading-sequence transition are different behaviors. Decide which coordinate system the interaction uses, then test its start, intermediate and final states.

Also inspect transform origin, background position and custom shadow offsets during an audit. Their visual meaning may depend on direction, but no global RTL switch can infer that meaning. A cast-light shadow can stay fixed; a shadow indicating the hidden edge of a scrolling queue may need a counterpart.

Avoid using horizontal mirroring on an entire component to make its animation look plausible. Text, icons and content can all be mirrored together. Move the intended surface and keep its contents readable.

R033 covers a horizontal translation that moves an element off-screen in RTL. R032 covers direction-sensitive shadow x-offsets without an RTL counterpart. Other animation semantics still need interaction testing.

Audit responsive utilities and Arabic text together#

A component may pass at its base size and break when md:pl-8 or lg:text-left activates. Search the entire class list, including responsive and state prefixes. Changing only the unprefixed utility leaves the larger layout's physical instruction intact.

Use responsive logical utilities such as ps-4 md:ps-8. For a column-to-row component, inspect whether an auto margin or spacing rule still expresses the intended relationship after the main axis changes. Tailwind's responsive variants apply at configured breakpoints; use the project's actual breakpoint values in the test matrix.

The digitization queue should accommodate a longer manuscript title before falling back to truncation. A flexible text item may need min-w-0 to shrink within its row; Tailwind supplies minimum-width utilities for that constraint. Check neighboring buttons too, since making the text shrink does not guarantee the actions remain usable.

Do not apply truncate to every translated label. It combines a single-line presentation with clipping and an ellipsis. MDN explains the interaction of text overflow, white space and overflow. If reviewers need the complete manuscript title to distinguish records, wrapping or an expandable detail view may serve the task better.

Inspect typography utilities copied from English display text. tracking-widest does not become suitable for Arabic when alignment changes. Remove inappropriate tracking from Arabic text, inspect the actual rendered font, and test letters with marks in multiline content. Tailwind documents letter spacing and line height independently; changing one does not repair the other.

R051 covers letter spacing applied to Arabic text. R042 covers clipped text wider than its box with hidden overflow and no ellipsis. A deliberately truncated title can still be unusable even when it does not fit that check's description. Decide whether the content remains sufficient for the review task.

Check class generation before debugging the cascade#

A missing utility and an overridden utility are different failures. In DevTools, first check whether the expected rule exists in the stylesheet. Then inspect which declaration wins and which physical side the logical property maps to.

Do not construct direction-dependent utility names from fragments:

tsx
// Problem: Tailwind cannot discover these complete utility names herefunction QueueIndent({ rtl }: { rtl: boolean }) {  return <div className={`m${rtl ? 'r' : 'l'}-4`}>ملاحظات التدقيق</div>;}

For this reading-start indentation, use one complete logical utility:

tsx
function QueueIndent() {  return <div className="ms-4">ملاحظات التدقيق</div>;}

The component now follows inherited direction without a separate direction prop. If another decision truly requires conditional classes, include complete literal class strings in the source. Tailwind's source-detection guidance explains why interpolation is not evaluated during scanning.

For a shared component package, confirm that its source is included in generation. In v4, explicit @source registration can cover files outside normal detection; in v3, check the configured content paths. A style that appears locally because another screen uses the class can disappear in a smaller production build.

Finally, inspect library CSS and arbitrary values. [margin-left:18px] is still physical CSS despite being inside a Tailwind class. Reordering words in the HTML class attribute is not a reliable way to resolve conflicting utilities; inspect stylesheet order, specificity and layers instead.

Check class-combining helpers at component boundaries too. Passing className="ps-6" does not inherently replace a base component's pl-3; ordinary string concatenation keeps both. A utility-merging library may remove some conflicts, but its result depends on its own version and configuration. Inspect the final rendered class list, then the computed padding in both directions. Prefer an explicit component option when a consumer needs to replace its spacing contract. Tailwind's utility-composition guidance discusses conflicting utilities and why their order in the attribute does not establish precedence.

Verify the component in both directions before shipping#

Build a small fixture page containing the queue notice, review actions, floating badge, open menu and nested English log. Render it once in LTR and once in RTL, using the production stylesheet.

  • Compare the English screenshot before and after replacing physical utilities.
  • Check Arabic at narrow, intermediate and wide widths, including both sides of layout breakpoints.
  • Use long manuscript titles, multiline review notes and disabled actions.
  • Open overlays, follow keyboard focus and test directional controls.
  • Inspect the nested LTR region so ancestor-based variants cannot hide there.
  • Repeat after a Tailwind upgrade, paying attention to child-spacing rules and generated selectors.

Keep failures specific. If a badge is misplaced, record its containing block, direction and computed inline inset. If spacing doubles, inspect both the physical and logical margins. If text disappears, inspect its width and overflow behavior before replacing unrelated RTL classes.

Use measurements to support the screenshot. For the notice, compare starting-side border width and padding against the opposite side. For the badge, compare its distance from the preview's intended edge rather than from the viewport. For the action group, check the actual gap after wrapping and after hiding an unavailable action. Keep the theme and root font size fixed during the comparison; numeric spacing utilities can resolve differently when design tokens change. A directional regression test should isolate direction before a separate review evaluates a new spacing scale.

Logical layout also does not isolate mixed-direction values. A correctly spaced manuscript reference can still need suitable inline markup. Use bidi isolation for that separate text boundary instead of adding text-left to an entire Arabic row.

A free Ritla scan can surface direction-sensitive physical properties without RTL overrides on the rendered queue page; use the original English fixture to verify that the repair preserves its layout. Continue with converting LTR CSS to RTL for the remaining non-Tailwind styles, or testing across breakpoints when the defect appears only after a responsive utility activates.

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