RTL support helps websites show text and layout correctly for languages that read from right to left, like Arabic or Hebrew.
RTL (right-to-left) support in Bootsrap
<!-- Add 'dir="rtl"' attribute to <html> or <body> --> <html lang="ar" dir="rtl"> <!-- Bootstrap RTL CSS --> <link href="bootstrap.rtl.min.css" rel="stylesheet"> </html>
The dir="rtl" attribute tells the browser to display content from right to left.
Bootstrap provides a special RTL CSS file to flip layout and components automatically.
<html lang="ar" dir="rtl"> <head> <link href="bootstrap.rtl.min.css" rel="stylesheet"> </head> <body> <nav class="navbar navbar-expand-lg navbar-light bg-light"> <a class="navbar-brand" href="#">موقعي</a> </nav> </body> </html>
dir="rtl" on specific elements to make only parts of the page right-to-left.<div dir="rtl">
<p>هذا نص باللغة العربية.</p>
</div>This complete page uses Bootstrap's RTL CSS and sets the dir="rtl" attribute on the html tag. The navigation bar and text align correctly for Arabic readers.
<!DOCTYPE html> <html lang="ar" dir="rtl"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>مثال دعم RTL</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.rtl.min.css" rel="stylesheet"> </head> <body> <nav class="navbar navbar-expand-lg navbar-light bg-light"> <div class="container-fluid"> <a class="navbar-brand" href="#">موقعي</a> <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="تبديل التنقل"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="navbarNav"> <ul class="navbar-nav me-auto mb-2 mb-lg-0"> <li class="nav-item"> <a class="nav-link active" aria-current="page" href="#">الرئيسية</a> </li> <li class="nav-item"> <a class="nav-link" href="#">الميزات</a> </li> <li class="nav-item"> <a class="nav-link" href="#">الأسعار</a> </li> </ul> </div> </div> </nav> <main class="container mt-4"> <h1>مرحبًا بكم في موقعي</h1> <p>هذا مثال على صفحة تستخدم دعم RTL مع Bootstrap.</p> </main> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> </body> </html>
Always include the dir="rtl" attribute on the html or body tag for full page RTL support.
Use Bootstrap's bootstrap.rtl.min.css file instead of the regular CSS to flip layout and components automatically.
Test your page in different browsers to ensure RTL displays correctly and navigation works well.
RTL support is important for languages that read right to left.
Use dir="rtl" and Bootstrap's RTL CSS to make your site RTL-friendly.
This changes text direction, alignment, and layout automatically for RTL languages.
Practice
dir="rtl" to an HTML element do in a Bootstrap page?Solution
Step 1: Understand the role of
Thedirattributedirattribute sets the text direction for an element and its children.Step 2: Apply
Settingdir="rtl"meaningdir="rtl"changes text flow from right to left, important for RTL languages.Final Answer:
It changes the text direction to right-to-left for that element and its children. -> Option CQuick Check:
Text direction = right-to-left [OK]
- Thinking dir="rtl" changes font size
- Assuming it disables Bootstrap styles
- Confusing text centering with direction
Solution
Step 1: Recall Bootstrap RTL support method
Bootstrap does not use a specific class for RTL but provides a separate RTL CSS file.Step 2: Understand how to enable RTL in Bootstrap
To support RTL, you include the RTL version of Bootstrap CSS which adjusts layout and text direction automatically.Final Answer:
Bootstrap provides a separate RTL CSS file, not a class -> Option AQuick Check:
RTL support = separate CSS file [OK]
- Looking for a class like .rtl or .text-rtl
- Assuming direction is controlled by classes only
- Confusing CSS classes with HTML attributes
<div dir="rtl" class="container"> <p class="text-start">Hello</p> </div>
What will be the alignment of the paragraph text when Bootstrap RTL CSS is loaded?
Solution
Step 1: Understand
Settingdir="rtl"effect on text directiondir="rtl"flips the reading direction to right-to-left.Step 2: Analyze Bootstrap's
In RTL mode,.text-startclass in RTL mode.text-startaligns text to the right side, reversing the usual left alignment.Final Answer:
Text will be aligned to the right side of the container. -> Option BQuick Check:
Bootstrap RTL flips .text-start to right align [OK]
- Assuming .text-start always means left alignment
- Ignoring the effect of dir="rtl" on alignment
- Thinking text will be centered automatically
dir="rtl" to your page but the layout does not flip as expected. What is the most likely cause?Solution
Step 1: Check the role of Bootstrap RTL CSS
Bootstrap requires its RTL CSS file to flip layout and components properly.Step 2: Identify missing RTL CSS as the cause
If onlydir="rtl"is set but RTL CSS is missing, layout stays LTR.Final Answer:
You forgot to include Bootstrap's RTL CSS file. -> Option DQuick Check:
Missing RTL CSS = no layout flip [OK]
- Thinking dir="rtl" alone flips layout
- Believing Bootstrap lacks RTL support
- Applying dir="rtl" only to small elements
Solution
Step 1: Understand dynamic language direction needs
Supporting both LTR and RTL requires switching text direction and styles based on language.Step 2: Use JavaScript to toggle
Switchingdirand CSS filesdirattribute and loading the correct Bootstrap CSS (LTR or RTL) ensures proper layout and text flow.Final Answer:
Use JavaScript to toggledirattribute and switch between Bootstrap LTR and RTL CSS files. -> Option AQuick Check:
Dynamic RTL/LTR = toggle dir + CSS [OK]
- Using only RTL CSS for all languages
- Ignoring CSS switch, relying on browser defaults
- Trying to rewrite Bootstrap CSS manually
Ready to prove it?
Pass the test and this pattern moves unknown
