RTL

    We recommend getting familiar with Bootstrap first by reading through our Getting Started Introduction page. Once you’ve run through it, continue reading here for how to enable RTL.

    You may also want to read up on , as it powers our approach to RTL.

    The RTL feature is still experimental and will probably evolve according to user feedback. Spotted something or have an improvement to suggest? Open an issue, we’d love to get your insights.

    Required HTML

    There are two strict requirements for enabling RTL in Bootstrap-powered pages.

    1. Set on the <html> element.
    2. Add an appropriate lang attribute, like lang="ar", on the <html> element.

    From there, you’ll need to include an RTL version of our CSS. For example, here’s the stylesheet for our compiled and minified CSS with RTL enabled:

    Starter template

    You can see the above requirements reflected in this modified RTL starter template.

    1. <!doctype html>
    2. <html lang="ar" dir="rtl">
    3. <head>
    4. <!-- Required meta tags -->
    5. <meta charset="utf-8">
    6. <meta name="viewport" content="width=device-width, initial-scale=1">
    7. <!-- Bootstrap CSS -->
    8. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.rtl.min.css" integrity="sha384-XfhC/Sid4FIGSXYebcOtcSCRFkd/zZzAMVipf0bNWucloRvcKK2/dpVWodQbQ1Ek" crossorigin="anonymous">
    9. <title>مرحبا بالعالم!</title>
    10. </head>
    11. <body>
    12. <h1>مرحبا بالعالم!</h1>
    13. <!-- Optional JavaScript; choose one of the two! -->
    14. <!-- Option 1: Bootstrap Bundle with Popper -->
    15. <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-U1DAWAznBHeqEIlVSCgzq+c9gqGAJn5c/t99JyeKa9xxaYpSvHU5awsuZVVFIhvj" crossorigin="anonymous"></script>
    16. <!-- Option 2: Separate Popper and Bootstrap JS -->
    17. <!--
    18. <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/js/bootstrap.min.js" integrity="sha384-cn7l7gDp0eyniUwwAZgrzD06kc/tftFf19TOAs2zVinnD/C7E91j9yyk5//jjpt/" crossorigin="anonymous"></script>
    19. -->
    20. </body>
    21. </html>

    Our approach to building RTL support into Bootstrap comes with two important decisions that impact how we write and use our CSS:

    1. First, we decided to build it with the project. This gives us some powerful features for managing changes and overrides when moving from LTR to RTL. It also allows us to build two versions of Bootstrap from one codebase.

    2. Second, we’ve renamed a handful of directional classes to adopt a logical properties approach. Most of you have already interacted with logical properties thanks to our flex utilities—they replace direction properties like left and right in favor start and end. That makes the class names and values appropriate for LTR and RTL without any overhead.

    For example, instead of .ml-3 for margin-left, use .ms-3.

    Working with RTL, through our source Sass or compiled CSS, shouldn’t be much different from our default LTR though.

    Customize from source

    When it comes to , the preferred way is to take advantage of variables, maps, and mixins. This approach works the same for RTL, even if it’s post-processed from the compiled files, thanks to how RTLCSS works.

    Custom RTL values

    Which would output to the following for our default CSS and RTL CSS:

    1. /* bootstrap.css */
    2. dt {
    3. font-weight: 700 /* rtl:600 */;
    4. }
    5. dt {
    6. font-weight: 600;
    7. }

    In the case you’re using a custom font, be aware that not all fonts support the non-Latin alphabet. To switch from Pan-European to Arabic family, you may need to use /*rtl:insert: {value}*/ in your font stack to modify the names of font families.

    For example, to switch from Helvetica Neue Webfont for LTR to Helvetica Neue Arabic for RTL, your Sass code look like this:

    LTR and RTL at the same time

    Need both LTR and RTL on the same page? Thanks to , this is pretty straightforward. Wrap your @imports with a class, and set a custom rename rule for RTLCSS:

    1. "autoRename": true,
    2. "stringMap":[ {
    3. "name": "ltr-rtl",
    4. "priority": 100,
    5. "search": ["ltr"],
    6. "replace": ["rtl"],
    7. "options": {
    8. "scope": "*",
    9. "ignoreCase": false
    10. }
    11. } ]
    12. } */
    13. .ltr {
    14. @import "../node_modules/bootstrap/scss/bootstrap";
    15. }
    16. /*rtl:end:options*/

    After running Sass then RTLCSS, each selector in your CSS files will be prepended by .ltr, and .rtl for RTL files. Now you’re able to use both files on the same page, and simply use .ltr or .rtl on your components wrappers to use one or the other direction.

    Edge cases and known limitations

    While this approach is understandable, please pay attention to the following:

    1. When switching .ltr and .rtl, make sure you add dir and lang attributes accordingly.
    2. Loading both files can be a real performance bottleneck: consider some , and maybe try to load one of those files asynchronously.
    3. Nesting styles this way will prevent our form-validation-state() mixin from working as intended, thus require you tweak it a bit by yourself. .

    Additional resources