Skip to main content
Logo USWDS + Tailwind

Language selector

The consistent placement, interface, and behavior of the language selection component allows users to easily find and access content in the language the user is most comfortable in.

Examples

Toggle

Breakpoints

Mobile

320px

Mobile Lg

480px

Tablet

640px

Desktop

1024px
Twig
<a href="#" class="inline-block rounded font-bold leading-none text-white px-5 py-3 bg-blue-60v hover:bg-blue-warm-70v active:bg-blue-warm-80v focus:outline focus:outline-4 focus:outline-offset-4 focus:outline-blue-40v">
<span lang="en">Español</span>
</a>

This component requires the following JavaScript plugin:

Twig
<div x-dropdown>
<button x-dropdown:trigger class="rounded font-bold leading-none text-white px-5 py-3 bg-blue-60v hover:bg-blue-warm-70v active:bg-blue-warm-80v focus:outline focus:outline-4 focus:outline-offset-4 focus:outline-blue-40v">
Languages
</button>
<div x-dropdown:content class="outline-none bg-blue-warm-80v w-60 divide-y divide-gray-cool-10 z-30">
{% for language in languages %}
<a x-dropdown:item href="#" class="block text-white p-2 hover:underline focus:outline focus:outline-4 focus:-outline-offset-4 focus:outline-blue-40v">
<span lang="{{- language.lang -}}">
<strong>{{- language.label -}}</strong>
{% if language.translation %}
{{- '(' ~ language.translation ~ ')' -}}
{% endif %}
</span>
</a>
{% endfor %}
</div>
</div>

Component API

Root

  • x-dropdown

    Custom Alpine directive that marks the Dropdown Root.

Trigger

  • x-dropdown:trigger

    Custom Alpine directive that marks the Dropdown Trigger.

  • aria-controls

    Type: string

    Accessibility attribute that communicates that the Dropdown Trigger controls the state and visibility of the Dropdown Menu.

    Automatically handled with JavaScript.

  • aria-expanded

    Type: boolean
    Default: false

    Accessibility attribute that communicates whether the Dropdown Menu is expanded or collapsed.

    Automatically handled with JavaScript.

  • aria-haspopup

    Type: string

    Accessibility attribute that communicates that this component has an interactive popup element.

    Automatically handled with JavaScript.

Content

  • x-dropdown:content

    Custom Alpine directive that marks the Dropdown Content.

  • role

    Type: string
    Value: 'menu'

    Automatically handled with JavaScript.

  • aria-labelledby

    Type: string

    Accessibility attribute that links the Dropdown Content to the Dropdown Trigger via id.

    Automatically handled with JavaScript.

  • tabindex

    Type: number
    Value: -1

    Prevents users from tabbing to this element.

    Automatically handled with JavaScript.

Item

  • x-dropdown:item

    Custom Alpine directive that marks the Dropdown Item.

  • role

    Type: string
    Value: 'menuitem'

    Automatically handled with JavaScript.

  • tabindex

    Type: number
    Value: -1

    Prevents users from tabbing to this element.

    Automatically handled with JavaScript.

Keyboard Interactions

  • Down Arrow

    When focus is on Dropdown Trigger, opens and moves focus to Dropdown Content.

    When focus is on the Dropdown Content, moves focus to first Dropdown Item.

    When focus is on a Dropdown Item, moves focus to next Dropdown Item.

  • Up Arrow

    When focus is on Dropdown Trigger, opens and moves focus to Dropdown Content.

    When focus is on the Dropdown Content, moves focus to last Dropdown Item.

    When focus is on a Dropdown Item, moves focus to previous Dropdown Item.

  • Enter

    When focus is on an Dropdown Item, selects that item.

  • Escape

    When the Dropdown Content is open, closes the Dropdown Content and moves focus to the Dropdown Trigger.