jQuery Mobile Docs - Select

# Select Menus

Home Search

## Select menus

- Basics
- Options
- Methods
- Events

The select menu is based on a native `select` element, which is hidden from view and replaced with a custom-styled select button that matches the look and feel of the jQuery Mobile framework. The select menu is ARIA-enabled and keyboard accessible on the desktop as well. View the data- attribute reference to see all the possible attributes you can add to selects.

By default, the framework leverages the native OS options menu to use with the custom button. When the button is clicked, the native OS menu will open. When a value is selected and the menu closes, the custom button's text is updated to match the selected value. Please note that the framework also offers the possibility of having custom (non-native) select menus; see details at the bottom of this page and on the custom select menu page.

To add a select menu to your page, start with a standard `select` element populated with a set of `option` elements. Set the `for` attribute of the `label` to match the `id` of the `select` so they are semantically associated. It's possible to accessibly hide the label if it's not desired in the page layout, but we require that it is present in the markup for semantic and accessibility reasons.

The framework will find all `select` elements and automatically enhance them into select menus; there is no need to apply a `data-role` attribute. To prevent the automatic enhancement of a select, add `data-role="none"` attribute to the `select`.

    <label for="select-choice-0" class="select">Shipping method:</label>
    <select name="select-choice-0" id="select-choice-0">
       <option value="standard">Standard: 7 day</option>
       <option value="rush">Rush: 3 days</option>
       <option value="express">Express: next day</option>
       <option value="overnight">Overnight</option>
    </select>

This will produce a basic select menu. The default styles set the width of the input to 100% of the parent container and stacks the label on a separate line.

Shipping method:

## Mini version

For a more compact version that is useful in toolbars and tight spaces, add the `data-mini="true"` attribute to the element to create a mini version.

    <label for="select-choice-min" class="select">Shipping method:</label>
    <select name="select-choice-min" id="select-choice-min" data-mini="true">
       <option value="standard">Standard: 7 day</option>
       <option value="rush">Rush: 3 days</option>
       <option value="express">Express: next day</option>
       <option value="overnight">Overnight</option>
    </select>

This will produce a select that a not as tall as the standard version and has a smaller text size.

Shipping method:

## Field containers

Optionally wrap the selects in a container with the `data-role="fieldcontain"` attribute to help visually group it in a longer form.

    <div data-role="fieldcontain">
       <label for="select-choice-1" class="select">Shipping method:</label>
       <select name="select-choice-1" id="select-choice-1">
          <option value="standard">Standard: 7 day</option>
          <option value="rush">Rush: 3 days</option>
          <option value="express">Express: next day</option>
          <option value="overnight">Overnight</option>
       </select>
    </div>

The select input is now displayed like this:

Shipping method:

An example of a select with a long list of options:

Your state:

## Optgroups

The following example organizes the options into `optgroup` elements. Support for this feature in mobile selects is a bit spotty, but is improving.

Preferred delivery:

## Vertically grouped select inputs

To create a grouped set of select inputs, first add `select` and a corresponding `label`. Set the `for` attribute of the `label` to match the `id` of the `select` so they are semantically associated.

Because the `label` element will be associated with each individual select input, we recommend wrapping the selects in a `fieldset` element that has a `legend` which acts as the combined label for the grouped inputs.

Lastly, one needs to add the `data-role="controlgroup"` attribute to the `fieldset`, so it will be styled as a group.

    <div data-role="fieldcontain">
        <fieldset data-role="controlgroup">
            <legend>Date of Birth:</legend>

            <label for="select-choice-month">Month</label>
            <select name="select-choice-month" id="select-choice-month">
                <option>Month</option>
                <option value="jan">January</option>
                <!-- etc. -->
            </select>

            <label for="select-choice-day">Day</label>
            <select name="select-choice-day" id="select-choice-day">
                <option>Day</option>
                <option value="1">1</option>
                <!-- etc. -->
            </select>

            <label for="select-choice-year">Year</label>
            <select name="select-choice-year" id="select-choice-year">
                <option>Year</option>
                <option value="2011">2011</option>
                <!-- etc. -->
            </select>

        </fieldset>
    </div>

Date of Birth: Month
Day
Year

## Horizontally grouped select inputs

Select inputs can also be used for grouped sets with more than one related selection. To make a horizontal button set, add the `data-type="horizontal"` to the fieldset. Note that the buttons which trigger the select will resize depending on the currently selected option's value. Note that browsers without support for `display: inline-block;` will group the selects vertically, as above.

`<fieldset data-role="controlgroup" data-type="horizontal">`
Date of Birth: Month
Day
Year

## Calling the select menu plugin

The select menu plugin will auto initialize on any page that contains a select menu, without any need for a `data-role` attribute in the markup. However, you can directly call the select menu plugin on any selector, just like any normal jQuery plugin:

    $('select').selectmenu();

## Theming selects

You can specify any jQuery Mobile button `data-` attribute on a select element, too. In this example, we're setting the theme, icon and inline properties:

Actions

## Custom select menus

For the sake of advanced styling, the framework also offers a method of generating custom menus from existing select menu markup instead of the native OS menu. The custom menu supports disabled options and multiple selection (whereas native mobile OS support for both is inconsistent), adds an elegant way to handle placeholder values, and restores missing functionality on certain platforms such as `optgroup` support on Android.

Custom select menu docs

### More in this section

- Form elements
- Form basics
- Form element gallery
- Mini form element gallery
- Text inputs
- Search input
- Slider
- Flip toggle switch
- Radio buttons
- Checkboxes
- Select menus
- Theming forms
- Native form elements
- Submitting forms