Prototype edition
Chosen makes long select boxes easier to use while preserving the native form control underneath.
jQuery edition
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.
optgroup
inherit_optgroup_classes: true
$(".chosen-select-group-chips").chosen({inherit_optgroup_classes: true, width: "100%"});
new Chosen($("group-chip-multiple"), {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.
label
The disable_search_threshold option can be specified to hide the search input on single selects if there are n or fewer options.
disable_search_threshold
$(".chosen-select").chosen({disable_search_threshold: 10});
new Chosen($("chosen_select_field"),{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.
data-placeholder
placeholder
placeholder_text_single
placeholder_text_multiple
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:
hidden
selected
disabled
<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.
no_results_text
no_results_template
{search}
chosen:no_results
chosen:no_results_clear
$(".chosen-select").chosen({no_results_template: "No match for {search}."});
new Chosen($("chosen_select_field"),{no_results_template: "No match for {search}."});
No search yet.
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:maxselected
$(".chosen-select").bind("chosen:maxselected", function () { ... });
new Chosen($("chosen_select_field"),{max_selected_options: 5});
$("chosen_select_field").observe("chosen:maxselected", function(evt) { ... });
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.
max_items_shown
max_selected_options
$(".chosen-select-summary").chosen({max_items_shown: 2});
new Chosen($("summary-select"), {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.
Atlas, Beacon; Comet
Unknown
$(".chosen-select-paste").chosen({paste_multiple_values: true});
new Chosen($("paste-select"), {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({ new Chosen($("chosen_select_field"), { allow_select_all: true, allow_deselect_all: true }); Try searching for “bear” first American Black Bear Asiatic Black Bear Brown Bear Giant Panda Sloth Bear Sun Bear Polar Bear Spectacled Bear
new Chosen($("chosen_select_field"), { 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.
allow_single_deselect: true
You can set right-to-left text by setting rtl: true
rtl: true
$(".chosen-select").chosen({rtl: true});
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( … );
Note: Prototype doesn't offer support for triggering standard browser events. Event.simulate is required to trigger the change event when using the Prototype version.
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");
Event.fire($("form_field"), "chosen:updated");
To destroy Chosen and revert back to the native select:
$("#form_field").chosen("destroy");
To destroy Chosen and revert back to the native select, call destroy on the Chosen instance:
destroy
chosen = new Chosen($("form_field")); // ...later 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.
chosen-jjj/remote
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"); } });
ChosenRemote.connectRemoteSelect($("remote-select"), { load: loadProjects, subscribe: function(search) { var field = $("remote-select"); var handler = function(event) { search(event.memo.search_term); }; field.observe("chosen:search_updated", handler); return function() { field.stopObserving("chosen:search_updated", handler); }; }, update: function() { $("remote-select").fire("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.
rem
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"};
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%"});
new Chosen($("chosen_select_field"),{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:
dropdown_width
$("#width-dropdown").chosen({width: "180px", dropdown_width: "300px"});
new Chosen($("width-dropdown"), {width: "180px", dropdown_width: "300px"});
Set width: false to leave the generated container's width to CSS:
width: false
$("#css-width-select").chosen({width: false});
new Chosen($("css-width-select"), {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.
recalculate_width_on_update
chosen:updated
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.
overflow: hidden
$("#clipped-dropdown").chosen({dropdown_position: "fixed"});
new Chosen($("clipped-dropdown"), {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});
new Chosen($("mobile-project"), {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.
open_on_label_click: false
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({ new Chosen($("recipe-search"), { 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"); } }); Try an alias or reordered phrase Café Blue Atlas Project Beacon Studio 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({ new Chosen($("recipe-word-boundary"), { search_word_boundary: "^|[^A-Za-zÆØÅæøå]" }); Try a Danish word boundary Frank Møller Team Atlas 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. Search from the start of an option <01M Fund Other <01M Fund X<01M Fund 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. Choose a country or Other Australia Germany Other Country name 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({ new Chosen($("recipe-matcher"), { search_matcher: function(query, item) { return !item.group && item.value.indexOf("SKU-") === 0 && item.text.toLowerCase().indexOf(query.toLowerCase()) !== -1; } }); Only SKU-backed projects appear Atlas Beacon Comet
new Chosen($("recipe-search"), { 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({ new Chosen($("recipe-word-boundary"), { search_word_boundary: "^|[^A-Za-zÆØÅæøå]" }); Try a Danish word boundary Frank Møller Team Atlas 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. Search from the start of an option <01M Fund Other <01M Fund X<01M Fund 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. Choose a country or Other Australia Germany Other Country name 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({ new Chosen($("recipe-matcher"), { search_matcher: function(query, item) { return !item.group && item.value.indexOf("SKU-") === 0 && item.text.toLowerCase().indexOf(query.toLowerCase()) !== -1; } }); Only SKU-backed projects appear Atlas Beacon Comet
new Chosen($("recipe-word-boundary"), { 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.
enable_split_word_search: false
search_contains: true
<01M
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.
data-chosen-always-visible
Country name
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.
search_matcher
$("#recipe-matcher").chosen({ new Chosen($("recipe-matcher"), { search_matcher: function(query, item) { return !item.group && item.value.indexOf("SKU-") === 0 && item.text.toLowerCase().indexOf(query.toLowerCase()) !== -1; } }); Only SKU-backed projects appear Atlas Beacon Comet
new Chosen($("recipe-matcher"), { 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.
search_contains
highlight_prefix_matches
$(".chosen-select-prefix-highlight").chosen({ 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. new Chosen($("prefix-preferred"), { search_contains: true, highlight_prefix_matches: true }); Default contains search ReactAngularReact Native Prefer a label prefix ReactAngularReact Native
new Chosen($("prefix-preferred"), { 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({ new Chosen($("recipe-create"), { create_option: true, persistent_create_option: true, skip_no_results: true }); Try adding a project Atlas Beacon Comet
new Chosen($("recipe-create"), { 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({ new Chosen($("recipe-selected"), { display_selected_value: true, deselect_selected_results: true, hide_results_on_select: false }); Open to remove a selected result Atlas Team Beacon Crew Comet Project
new Chosen($("recipe-selected"), { 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 });
new Chosen($("recipe-shift-range"), { 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.
select-by-group
readonly
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.
aria-invalid="true"
required
Choose one fruit before continuing.
Choose at least one fruit.
Using Chosen is easy as can be.
$(".chosen-select").chosen()
Yes! You can find them on the options page.
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.
Yes. See the styling guide and CSS examples.
Yes. See the CSS and Sass examples for matched search text.
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.
See the 4.0 migration guide for generated-markup, search-input, and package-entry changes.
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.
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().
$.fn.chosen.browser_is_supported()
There still is!
To check support before initializing the Prototype plugin, call Chosen.browser_is_supported().
Chosen.browser_is_supported()