Choose a country to see the optional “Add another...” hint beside the selected chip.
Give each optgroup a class and set inherit_optgroup_classes: true. Selected chips then carry their group class for styling. Try selecting one item from each group.
$(".chosen-select-group-chips").chosen({inherit_optgroup_classes: true, width: "100%"});
Chosen automatically highlights selected options and removes disabled and / or hidden options. Try Kodiak Bear, which has a label attribute but no option text.
The disable_search_threshold option can be specified to hide the search input on single selects if there are n or fewer options.
$(".chosen-select").chosen({disable_search_threshold: 10});
Chosen automatically sets the default field text ("Choose a country...") by reading the select element's data-placeholder value. Without that attribute, it uses the select's placeholder, then a type-specific placeholder_text_single or placeholder_text_multiple option, then the shared placeholder_text option. Otherwise it shows "Select an Option" or "Select Some Options". An explicitly empty value removes the placeholder text.
<select data-placeholder="Choose a country..." multiple class="chosen-select">
Note: on single selects, the first element is assumed to be selected by the browser. To take advantage of the default text support, you will need to include a blank option as the first element of your select list - or include an element with the same label as the placeholder and set the hidden, selected and disabled attributes on it for a more graceful degradation on devices Chosen does not support:
<option value="" selected disabled hidden>Choose a country...</option>
Set the message with no_results_text, or place the search term with no_results_template and its {search} marker. Type an unmatched search, then clear it to see the chosen:no_results and chosen:no_results_clear events below.
$(".chosen-select").chosen({no_results_template: "No match for {search}."});
You can easily limit how many options the user can select:
$(".chosen-select").chosen({max_selected_options: 5});
If you try to select another option with limit reached chosen:maxselected event is triggered:
$(".chosen-select").bind("chosen:maxselected", function () { ... });
Use max_items_shown to keep a long multiple selection compact. The remaining choices are still selected; the summary button reveals them without changing the underlying select. This is separate from max_selected_options, which limits how many choices can be selected.
$(".chosen-select-summary").chosen({max_items_shown: 2});
Copy Atlas, Beacon; Comet, click the search area below, and paste. Chosen selects those existing options. Try adding Unknown to see unmatched text stay available for editing.
$(".chosen-select-paste").chosen({paste_multiple_values: true});
Multiple selects can add opt-in bulk actions. Select all applies to the currently filtered enabled options; Deselect all clears every enabled choice. With an empty search, use Command/Ctrl+A to select all or Command/Ctrl+Shift+A to deselect all.
$(".chosen-select").chosen({
allow_select_all: true,
allow_deselect_all: true
});
When a single select box isn't a required field, you can set allow_single_deselect: true and Chosen will add a UI element for option deselection. The selection can also be cleared with Backspace or Delete when the closed control is focused. Enter opens its dropdown, and Up from the first highlighted result closes it. Deselection requires a blank first option.
You can set right-to-left text by setting rtl: true
$(".chosen-select").chosen({rtl: true});
-
Observing Form Field Changes
When working with form fields, you often want to perform some behavior after a value has been selected or deselected. Whenever a user selects a field in Chosen, it triggers a "change" event on the original form field. That lets you do something like this:
$("#form_field").chosen().change( … );
-
Updating Chosen Dynamically
If you need to update the options in your select field and want Chosen to pick up the changes, you'll need to trigger the "chosen:updated" event on the field. Chosen will re-build itself based on the updated content.
$("#form_field").trigger("chosen:updated");
-
Destroying Chosen
To destroy Chosen and revert back to the native select:
$("#form_field").chosen("destroy");
Type at least two letters, then select a returned project and search again. The opt-in chosen-jjj/remote API loads a bounded page, ignores stale responses, and keeps selected values in the native select. Replace the demo provider with your server request. See the remote search guide.
ChosenRemote.connectRemoteSelect(document.querySelector("#remote-select"), {
load: loadProjects,
subscribe: function(search) {
var field = $("#remote-select");
var handler = function(event, data) {
search(data.search_term);
};
field.on("chosen:search_updated", handler);
return function() { field.off("chosen:search_updated", handler); };
},
update: function() { $("#remote-select").trigger("chosen:updated"); }
});
Chosen's default dimensions stay familiar, while CSS variables can use relative units. This select uses rem for text, spacing, and its SVG icons. Change your browser's root font size or zoom to see it scale. See the styling reference for the CSS recipe.
Set adapter-local defaults once before initializing a group of controls. A per-select option still wins. These two controls use one shared prompt and one local override:
$.fn.chosen.defaults = {placeholder_text_single: "Shared prompt"};
Give one select its own options in markup. This example hides search, allows clearing the selection, and sets its width without a separate JavaScript configuration object.
<select data-disable-search="true" data-allow-single-deselect="true" data-width="100%">...</select>
Using a custom width with Chosen is as easy as passing an option when you create Chosen:
$(".chosen-select").chosen({width: "95%"});
Use dropdown_width when the results need more room than the closed control. A custom-width dropdown floats as a separate surface so the unequal edges do not look accidentally connected:
$("#width-dropdown").chosen({width: "180px", dropdown_width: "300px"});
Set width: false to leave the generated container's width to CSS:
$("#css-width-select").chosen({width: false});
#css_width_select_chosen { width: 24rem; max-width: 100%; }
For options loaded later, enable recalculate_width_on_update so chosen:updated can resize the control.
Open this control inside a short overflow: hidden panel. The opt-in fixed position keeps its results visible outside the panel. Scroll the page while it is open to see it stay aligned.
$("#clipped-dropdown").chosen({dropdown_position: "fixed"});
On a narrow touch screen, this opt-in picker fills the visible viewport. Search or scroll the longer list, then choose a project or use Close. On desktop it remains a regular dropdown.
$("#mobile-project").chosen({mobile_fullscreen: true});
Use labels just like you would with a standard select. This demo sets open_on_label_click: false, so clicking either label focuses its closed Chosen control without opening the dropdown. You can also drag across a label to select its text without activating Chosen.
Search “espresso” for the Café alias, “cafe” without the accent, or “project blue” with the words out of order. This example also waits for two characters before showing results. See the options reference for custom matchers, result limits, and search timing.
$("#recipe-search").chosen({
split_search_terms: true,
min_search_length: 2,
normalize_search_text: function(text) {
if (text.normalize) {
return text.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
}
return text.replace(/[éèêë]/g, "e");
}
});
JavaScript's default word boundary can treat an accented letter as punctuation. This opt-in boundary keeps Danish letters within a word. Search “ller” (no match), then “Møl” (one match). Supply a boundary pattern for the languages your options use.
$("#recipe-word-boundary").chosen({
search_word_boundary: "^|[^A-Za-zÆØÅæøå]"
});
To match only from the start, including punctuation, combine enable_split_word_search: false with search_contains: true. Try searching for <01M; the option with a preceding word stays hidden.
An option marked data-chosen-always-visible remains available when a search has no match. Search for “France” here, choose “Other”, then enter a country name. The original select still holds the submitted choice.
A custom search_matcher can replace built-in matching. This one only offers SKU-backed options, even before typing. Custom matches have no automatic text highlighting.
$("#recipe-matcher").chosen({
search_matcher: function(query, item) {
return !item.group && item.value.indexOf("SKU-") === 0 &&
item.text.toLowerCase().indexOf(query.toLowerCase()) !== -1;
}
});
Type “a” in both controls. search_contains keeps React in the results, while highlight_prefix_matches makes Angular the initial keyboard choice. The list stays in the original order.
$(".chosen-select-prefix-highlight").chosen({
search_contains: true,
highlight_prefix_matches: true
});
Type a new project name and choose “Add project” to append it to the original multiple select. Existing matches remain available; an exact match does not offer a duplicate.
$("#recipe-create").chosen({
create_option: true,
persistent_create_option: true,
skip_no_results: true
});
The closed control can display option values while its dropdown keeps the labels. Open this multiple select and click a selected result to remove it. The underlying select still holds the actual values.
$("#recipe-selected").chosen({
display_selected_value: true,
deselect_selected_results: true,
hide_results_on_select: false
});
Select Atlas, reopen the list if needed, then Shift-click Delta. Chosen adds the visible options between them, skips the disabled Comet option, and leaves any existing choices selected.
$("#recipe-shift-range").chosen({ shift_select_range: true });
On a multiple select, select-by-group makes each optgroup label select its available options. The separate readonly control keeps its value enabled for form submission while preventing changes.
Set aria-invalid="true" on the original select when your application reports an error. The red border is opt-in; a native required field does not change Chosen's default appearance on its own. Use Check validity below to see where the browser places its required-field message.
Choose one fruit before continuing.
Choose at least one fruit.
Using Chosen is easy as can be.
- Download the plugin and copy the chosen files to your app.
- Activate the plugin on the select boxes of your choice:
$(".chosen-select").chosen()
- Disco.
-
Do you have all the available options documented somewhere?
Yes! You can find them on the options page.
-
Something doesn't work. Can you fix it?
Yes! Please report all issues using the GitHub issue tracking tool. Please include the plugin version (jQuery or Prototype), browser and OS. The more information provided, the easier it is to fix a problem.
-
Can I customize Chosen's appearance?
Yes. See the styling guide and CSS examples.
-
Can I change how matching search text is highlighted?
Yes. See the CSS and Sass examples for matched search text.
-
How does Tab work in a single select?
When the dropdown is open, Tab or Shift+Tab chooses the highlighted result and moves focus to the next or previous field. The results list itself is not an extra Tab stop.
-
What changed when upgrading from 3.x to 4.0?
See the 4.0 migration guide for generated-markup, search-input, and package-entry changes.
-
Can I press and drag onto a result?
Yes. Pressing the closed control, dragging onto a result, and releasing selects that result. Releasing a mouse or pen over a result after pressing outside Chosen leaves the selection unchanged.
-
What browsers are supported?
Chosen's original compatibility target includes Chrome, Firefox, Safari, and Internet Explorer 9. The full automated browser suite runs in Chrome with jQuery 4.0, 3.5, 1.12, and 1.7, plus Prototype 1.7. A focused Firefox test covers scrolled single-select Tab navigation in both adapters. Safari and Internet Explorer 9 are not covered by automated desktop tests.
To check support before initializing the jQuery plugin, call $.fn.chosen.browser_is_supported().
-
Didn't there used to be a Prototype version of Chosen?
There still is!