Language Switch

A pill-shaped language dropdown - the trigger opens the menu as a top-layer popover (the same pattern as the Dropdown Popover), zero JavaScript. Flags are tiny SVG files from img/flags/ - emoji flags don't render on Windows.

Language Switcher

The trigger shows the flag and code of the active language. The list opens from the right edge (.dropdown-menu-end), so it works safely as the last item in the navbar. The active item shows a checkmark. The img/flags/ folder contains only the flags of the languages offered in the project (individual SVG files at ~200 B each, inserted via <img>) - each loads once and is cached for the whole site.

<button class="language-switch-trigger" popovertarget="lang-menu" title="Change language">
  <span class="language-switch-flag"><img src="img/flags/gb.svg" width="20" height="15" alt=""></span>
  <span>EN</span>
</button>

<!-- [popover] = top layer; the menu anchors itself to the button automatically -->
<div class="dropdown-menu dropdown-menu-end language-switch-menu" popover id="lang-menu">
  <a href="#" class="dropdown-item language-switch-item">
    <span class="language-switch-flag"><img src="img/flags/gb.svg" width="20" height="15" alt=""></span>
    <span class="language-switch-name">English</span>
    <span class="language-switch-check"><svg aria-hidden="true" viewBox="0 0 256 256" fill="currentColor"><path d="M229.66,77.66l-128,128a8,8,0,0,1-11.32,0l-56-56a8,8,0,0,1,11.32-11.32L96,188.69,218.34,66.34a8,8,0,0,1,11.32,11.32Z"/></svg></span>
  </a>
  <a href="#" class="dropdown-item language-switch-item">
    <span class="language-switch-flag"><img src="img/flags/pl.svg" width="20" height="15" alt=""></span>
    <span class="language-switch-name">Polski</span>
  </a>
</div>