Skip to the content
Konstruktor UI

Website pieces

Language switcher

Every language is named in itself, the way its readers know it: Srpski, Српски, English, Deutsch, 中文. .kui-lang-switch__list is a row of links that works without a script; <kui-lang-switch> around a select opens the chosen address.

<kui-lang-switch> needs kui.js; the markup works without it as described below

Examples

As links

Each link carries hreflang and lang, so a screen reader pronounces the name in its own language. The current language has aria-current="true".

HTML
<nav class="kui-lang-switch" aria-label="Language">
  <ul class="kui-lang-switch__list">
    <li><a href="#lang-sr-latn" hreflang="sr-Latn" lang="sr-Latn">Srpski</a></li>
    <li><a href="#lang-sr-cyrl" hreflang="sr-Cyrl" lang="sr-Cyrl">Српски</a></li>
    <li><a href="#lang-en" hreflang="en" lang="en" aria-current="true">English</a></li>
    <li><a href="#lang-sv" hreflang="sv" lang="sv">Svenska</a></li>
    <li><a href="#lang-de" hreflang="de" lang="de">Deutsch</a></li>
    <li><a href="#lang-fr" hreflang="fr" lang="fr">Français</a></li>
    <li><a href="#lang-it" hreflang="it" lang="it">Italiano</a></li>
    <li><a href="#lang-pt" hreflang="pt" lang="pt">Português</a></li>
    <li><a href="#lang-zh" hreflang="zh" lang="zh">中文</a></li>
  </ul>
</nav>

As a select

Each option carries data-href, the address of the page in that language. The element opens it on change and sends kui-change with the language.

HTML
<kui-lang-switch>
  <svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#globe"></use></svg>
  <label class="kui-visually-hidden" for="lang-select">Language</label>
  <div class="kui-select">
    <select id="lang-select" class="kui-lang-switch__select">
      <option value="sr-Latn" lang="sr-Latn" data-href="#lang-sr-latn">Srpski</option>
      <option value="sr-Cyrl" lang="sr-Cyrl" data-href="#lang-sr-cyrl">Српски</option>
      <option value="en" lang="en" data-href="#lang-en" selected>English</option>
      <option value="sv" lang="sv" data-href="#lang-sv">Svenska</option>
      <option value="de" lang="de" data-href="#lang-de">Deutsch</option>
      <option value="fr" lang="fr" data-href="#lang-fr">Français</option>
      <option value="it" lang="it" data-href="#lang-it">Italiano</option>
      <option value="pt" lang="pt" data-href="#lang-pt">Português</option>
      <option value="zh" lang="zh" data-href="#lang-zh">中文</option>
    </select>
  </div>
</kui-lang-switch>

Classes and attributes

nav.kui-lang-switch, .kui-lang-switch__list
The links version. Works without a script.
<kui-lang-switch>
Wraps an icon, a hidden label and a .kui-select. Event: kui-change with detail.lang.
option data-href
The address the element opens when this language is chosen.
hreflang, lang
On every link or option: the language of the target page and of the name itself.
aria-current="true"
On the link of the language now shown.

Keyboard

Tab
Moves through the links, or to the select.
Arrow keys
In the select, change the language. Most browsers open the page at once on a change, so the select version suits a footer best.

Accessibility

  • The switcher is a nav named “Language” (in the page’s language), so it can be found as a landmark.
  • lang on each name lets a screen reader say “Deutsch” in German and “中文” in Chinese.
  • Never use flags: a flag is a country, not a language.

Do and do not

Do

  • Name each language in itself, and keep the same order on every page.
  • Link to the same page in the other language, not to its home page.

Do not

  • Do not translate the names (“German” instead of “Deutsch”).
  • Do not guess the language from the location; offer the switcher.