DEV Community

Cover image for RTL Mastery: Beyond Just dir="rtl"
Syed Ahmed Mohi Uddin Hasan
Syed Ahmed Mohi Uddin Hasan

Posted on

RTL Mastery: Beyond Just dir="rtl"

  1. When building for the KSA market, many developers think adding dir="rtl" to the tag is the finish line. In reality, that is just the starting blocks. Truly high-performance, localised apps require a "mirror-first" mindset to ensure a "pixel-perfect" experience for Arabic-speaking users.

In my experience launching production sites like DarElite, I've found that deep RTL support is what separates a translated site from a truly localised one. Here is a guide on going beyond the basics.

  1. Use CSS Logical Properties
  2. Stop thinking in "left" and "right." Use logical properties to let the browser handle the heavy lifting based on the document direction.
  3. Margin/Padding: Use margin-inline-start instead of margin-left.
  4. Borders: Use border-end-start-radius for specific corners.
  5. Tailwind Strategy: If you use Tailwind CSS, leverage the start and end utilities (e.g., ps-4 instead of pl-4).

  6. Icons: To Mirror or Not to Mirror?

  7. This is where most UI/UX bugs hide. Not every icon should be flipped.

  8. Mirror these: Progress bars, directional arrows (back/forward), and icons representing movement (like a bicycle).

  9. Don't mirror these: Checkmarks, clock faces, and media playback buttons (Play/Pause/Seek) generally stay the same.

  10. Handling Bidirectional (BiDi) Text

  11. In technical or business apps, you will often have "Mixed Direction" content—like an English email address or a phone number inside an Arabic sentence.

  12. The Fix: Use the (Bi-Directional Isolation) tag for user-generated content to prevent the layout from breaking when different scripts collide.

  13. Performance in RTL Layouts

  14. Localised apps often struggle with layout shifts during the "direction swap."

Tip: Ensure your CSS architecture is "direction-agnostic" from the start. By refining component architecture, I’ve managed to maintain 100% Lighthouse scores while supporting complex RTL layouts.

Top comments (0)