Course contentsShow
← Web Development
Lesson 2527 of 2,98245. InternationalizationFree lesson

RTL in CSS Frameworks

Configure Tailwind, Bootstrap, or custom frameworks to generate RTL-compatible utility classes.

RTL in CSS Frameworks

You'll learn how to configure popular CSS frameworks like Tailwind and Bootstrap to automatically generate RTL-compatible utility classes and styles.

The Challenge

Most CSS frameworks are built with left-to-right (LTR) languages in mind. Their utility classes assume LTR directionality: ml-4 means "margin-left," pr-2 means "padding-right," and so on. When you switch to RTL mode using dir="rtl", these utilities don't automatically flip, leaving your layout broken.

Framework Solutions

Tailwind CSS provides built-in RTL support through the dir configuration and logical property variants. You can enable RTL-aware utilities that automatically flip:

/* Instead of ml-4 (margin-left), use: */
.ms-4  /* margin-inline-start - flips automatically */
.pe-2  /* padding-inline-end - flips automatically */

Tailwind's rtl: variant lets you apply conditional styles:

<div class="ml-4 rtl:mr-4 rtl:ml-0">
  <!-- Margin adjusts based on direction -->
</div>

Bootstrap 5 offers RTL support via a separate compiled stylesheet (bootstrap.rtl.css) or by setting the $enable-rtl Sass variable during compilation. This generates mirrored versions of all utilities automatically.

Custom frameworks require manual configuration: generate logical property utilities (margin-inline-start instead of margin-left) or build a compilation step that creates RTL-specific stylesheets with flipped directional properties.

Think of It Like This

A framework-generated RTL setup is like having a smart translator for your styles—instead of manually rewriting every spacing and positioning rule, the framework automatically generates direction-aware versions that respond to the dir attribute.

Key Takeaway: Configure your CSS framework to generate RTL-compatible utilities using logical properties or directional variants, avoiding manual style overrides for every RTL context.