Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html lang="en" dir="ltr">
<head>
  <meta charset="UTF-8" />
  <title>RTL Navigation Menu Fix</title>
</head>
<body>
  <div class="container">
    <button id="switch-btn">Switch to Arabic</button>
    <button id="fix-btn" style="display: none;">Apply Fix</button>

    <h1 id="heading">Navigation Menu</h1>

    <!-- Problematic Navigation Menu -->
    <nav>
      <ul class="nav-menu" id="nav-menu">
        <li>Home</li>
        <li>About</li>
        <li>Services</li>
        <li>Contact</li>
      </ul>
    </nav>
  </div>
</body>
</html>
              
            
!

CSS

              
                body {
  font-family: Arial, sans-serif;
  margin: 20px;
  background: #f9f9f9;
}

.container {
  background: #fff;
  padding: 20px;
  border-radius: 8px;
}

#switch-btn,
#fix-btn {
  margin-bottom: 1rem;
  margin-right: 0.5rem;
  padding: 0.5rem 1rem;
  cursor: pointer;
  border: 1px solid #ccc;
  background-color: #eee;
  transition: background 0.3s, color 0.3s, border-color 0.3s;
}

#switch-btn:hover,
#fix-btn:hover {
  background-color: #ddd;
}

#fix-btn.fix-applied {
  background-color: #28a745; /* Green when fix is applied */
  color: white;
  border-color: #28a745;
}

#fix-btn.fix-applied:hover {
  background-color: #218838;
}

/* Problem: Default list order remains LTR in RTL mode */
.nav-menu {
  display: flex;
  gap: 1rem;
  list-style: none;
  padding: 0;
  direction: ltr; /* Default left-to-right order */
}

/* ✅ Fix: Reverse menu order for RTL */
.rtl-fix {
  flex-direction: row-reverse;
}
              
            
!

JS

              
                const switchBtn = document.getElementById('switch-btn');
const fixBtn = document.getElementById('fix-btn');
const heading = document.getElementById('heading');
const navMenu = document.getElementById('nav-menu');
const htmlEl = document.documentElement;

let isEnglish = true;
let fixApplied = false;

switchBtn.addEventListener('click', () => {
  if (isEnglish) {
    // Switch to Arabic (RTL)
    htmlEl.lang = 'ar';
    htmlEl.dir = 'rtl';

    heading.textContent = 'قائمة التنقل';
    switchBtn.textContent = 'Switch to English';

    // Update menu items to Arabic
    navMenu.innerHTML = `
      <li>الرئيسية</li>
      <li>حول</li>
      <li>الخدمات</li>
      <li>اتصل بنا</li>
    `;

    // Show fix button in Arabic mode
    fixBtn.style.display = 'inline-block';
    fixBtn.textContent = 'Apply Fix';
    fixBtn.classList.remove('fix-applied');

    fixApplied = false;
    isEnglish = false;
  } else {
    // Switch back to English (LTR)
    htmlEl.lang = 'en';
    htmlEl.dir = 'ltr';

    heading.textContent = 'Navigation Menu';
    switchBtn.textContent = 'Switch to Arabic';

    // Reset menu to English
    navMenu.innerHTML = `
      <li>Home</li>
      <li>About</li>
      <li>Services</li>
      <li>Contact</li>
    `;

    // Hide fix button in English mode
    fixBtn.style.display = 'none';
    fixBtn.classList.remove('fix-applied');

    fixApplied = false;
    isEnglish = true;
  }

  // Reset Fix when switching languages
  navMenu.classList.remove('rtl-fix');
});

fixBtn.addEventListener('click', () => {
  if (!fixApplied) {
    navMenu.classList.add('rtl-fix');
    fixBtn.textContent = 'Fix Applied';
    fixBtn.classList.add('fix-applied');
    fixApplied = true;
  } else {
    navMenu.classList.remove('rtl-fix');
    fixBtn.textContent = 'Apply Fix';
    fixBtn.classList.remove('fix-applied');
    fixApplied = false;
  }
});
              
            
!
999px

Console