Combobox
A select-like field built from a toggle button and a dropdown menu, with custom item content, live search and multiple selection.
Overview
A combobox looks like a select, but its options are ordinary HTML, so an item can hold an icon, a description, a badge or an image. It is a toggle button paired with a .dropdown-menu. JavaScript handles the menu, the selection, a hidden input for form submission and the keyboard.
Add data-bs-toggle="combobox" to a <button class="form-select combobox-toggle">, followed by a .dropdown-menu with .dropdown-item buttons. Every selectable item needs a data-bs-value.
<div class="w-100">
<button class="form-select combobox-toggle" type="button" data-bs-toggle="combobox" data-bs-placeholder="Select an item…" data-bs-name="option">
<span class="combobox-value"></span>
</button>
<div class="dropdown-menu">
<button class="dropdown-item" type="button" data-bs-value="1">Option one</button>
<button class="dropdown-item" type="button" data-bs-value="2">Option two</button>
<button class="dropdown-item" type="button" data-bs-value="3">Option three</button>
</div>
</div>Usage
Pre-selected value
Add .selected to an item to select it on load. The toggle text and the hidden input are filled in for you.
<div class="w-100">
<button class="form-select combobox-toggle" type="button" data-bs-toggle="combobox" data-bs-placeholder="Choose a role…" data-bs-name="role">
<span class="combobox-value"></span>
</button>
<div class="dropdown-menu">
<button class="dropdown-item" type="button" data-bs-value="admin">Admin</button>
<button class="dropdown-item selected" type="button" data-bs-value="editor">Editor</button>
<button class="dropdown-item" type="button" data-bs-value="viewer">Viewer</button>
</div>
</div>Form field
Wrap the combobox in a .mb-3 with a label, like any other field.
<div class="mb-3 w-100">
<label class="form-label">Country</label>
<button class="form-select combobox-toggle" type="button" data-bs-toggle="combobox" data-bs-placeholder="Pick a country…" data-bs-name="country">
<span class="combobox-value"></span>
</button>
<div class="dropdown-menu">
<button class="dropdown-item" type="button" data-bs-value="us">United States</button>
<button class="dropdown-item" type="button" data-bs-value="uk">United Kingdom</button>
<button class="dropdown-item" type="button" data-bs-value="ca">Canada</button>
</div>
</div>Descriptions and check mark
Use .dropdown-item-content with .dropdown-item-description for secondary text, and a .dropdown-item-check icon to mark the selected item.
<div class="w-100">
<button class="form-select combobox-toggle" type="button" data-bs-toggle="combobox" data-bs-placeholder="Select a role…" data-bs-name="access">
<span class="combobox-value"></span>
</button>
<div class="dropdown-menu">
<button class="dropdown-item" type="button" data-bs-value="admin">
<span class="dropdown-item-content">
<span>Admin</span>
<small class="dropdown-item-description">Full access to all resources</small>
</span>
<svg xmlns="http://www.w3.org/2000/svg" class="dropdown-item-check icon" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M5 12l5 5l10 -10" />
</svg>
</button>
<button class="dropdown-item" type="button" data-bs-value="editor">
<span class="dropdown-item-content">
<span>Editor</span>
<small class="dropdown-item-description">Can edit and publish content</small>
</span>
<svg xmlns="http://www.w3.org/2000/svg" class="dropdown-item-check icon" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M5 12l5 5l10 -10" />
</svg>
</button>
<button class="dropdown-item" type="button" data-bs-value="viewer">
<span class="dropdown-item-content">
<span>Viewer</span>
<small class="dropdown-item-description">Read-only access</small>
</span>
<svg xmlns="http://www.w3.org/2000/svg" class="dropdown-item-check icon" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M5 12l5 5l10 -10" />
</svg>
</button>
</div>
</div>Search
Place a .combobox-search input inside the menu, before the items, and the combobox filters the items by their text as you type. Add an optional .combobox-no-results message after the items. Set data-bs-search-normalize="true" to ignore accents.
<div class="w-100">
<button class="form-select combobox-toggle" type="button" data-bs-toggle="combobox" data-bs-placeholder="Select a country…" data-bs-search-normalize="true">
<span class="combobox-value"></span>
</button>
<div class="dropdown-menu">
<div class="combobox-search">
<input type="text" class="form-control form-control-sm combobox-search-input" placeholder="Search…" autocomplete="off" aria-label="Search" />
</div>
<button class="dropdown-item" type="button" data-bs-value="us">United States</button>
<button class="dropdown-item" type="button" data-bs-value="uk">United Kingdom</button>
<button class="dropdown-item" type="button" data-bs-value="ca">Canada</button>
<button class="dropdown-item" type="button" data-bs-value="au">Australia</button>
<button class="dropdown-item" type="button" data-bs-value="de">Germany</button>
<button class="dropdown-item" type="button" data-bs-value="fr">France</button>
<button class="dropdown-item" type="button" data-bs-value="pl">Poland</button>
<button class="dropdown-item" type="button" data-bs-value="jp">Japan</button>
<div class="combobox-no-results d-none">No results found</div>
</div>
</div>Groups
Use .dropdown-header to label groups of items and .dropdown-divider to separate them.
<div class="w-100">
<button class="form-select combobox-toggle" type="button" data-bs-toggle="combobox" data-bs-placeholder="Select a language…">
<span class="combobox-value"></span>
</button>
<div class="dropdown-menu">
<div class="dropdown-header">Frontend</div>
<button class="dropdown-item" type="button" data-bs-value="html">HTML</button>
<button class="dropdown-item" type="button" data-bs-value="css">CSS</button>
<div class="dropdown-divider"></div>
<div class="dropdown-header">Backend</div>
<button class="dropdown-item" type="button" data-bs-value="python">Python</button>
<button class="dropdown-item" type="button" data-bs-value="go">Go</button>
</div>
</div>Multiple selection
Add data-bs-multiple="true". Items toggle on click and the menu stays open. The toggle lists the chosen labels separated by commas and ends with “and N more” when they do not fit, and the hidden input holds a comma-separated list of the values.
<div class="w-100">
<button class="form-select combobox-toggle" type="button" data-bs-toggle="combobox" data-bs-placeholder="Select skills…" data-bs-name="skills" data-bs-multiple="true">
<span class="combobox-value"></span>
</button>
<div class="dropdown-menu">
<button class="dropdown-item selected" type="button" data-bs-value="html" aria-selected="true">HTML<svg xmlns="http://www.w3.org/2000/svg" class="dropdown-item-check icon" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M5 12l5 5l10 -10" />
</svg>
</button>
<button class="dropdown-item selected" type="button" data-bs-value="css" aria-selected="true">CSS<svg xmlns="http://www.w3.org/2000/svg" class="dropdown-item-check icon" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M5 12l5 5l10 -10" />
</svg>
</button>
<button class="dropdown-item selected" type="button" data-bs-value="js" aria-selected="true">JavaScript<svg xmlns="http://www.w3.org/2000/svg" class="dropdown-item-check icon" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M5 12l5 5l10 -10" />
</svg>
</button>
<button class="dropdown-item selected" type="button" data-bs-value="py" aria-selected="true">Python<svg xmlns="http://www.w3.org/2000/svg" class="dropdown-item-check icon" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M5 12l5 5l10 -10" />
</svg>
</button>
<button class="dropdown-item" type="button" data-bs-value="rb">Ruby<svg xmlns="http://www.w3.org/2000/svg" class="dropdown-item-check icon" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M5 12l5 5l10 -10" />
</svg>
</button>
<button class="dropdown-item" type="button" data-bs-value="go">Go<svg xmlns="http://www.w3.org/2000/svg" class="dropdown-item-check icon" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M5 12l5 5l10 -10" />
</svg>
</button>
<button class="dropdown-item" type="button" data-bs-value="php">PHP<svg xmlns="http://www.w3.org/2000/svg" class="dropdown-item-check icon" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M5 12l5 5l10 -10" />
</svg>
</button>
<button class="dropdown-item" type="button" data-bs-value="java">Java<svg xmlns="http://www.w3.org/2000/svg" class="dropdown-item-check icon" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M5 12l5 5l10 -10" />
</svg>
</button>
<button class="dropdown-item" type="button" data-bs-value="rust">Rust<svg xmlns="http://www.w3.org/2000/svg" class="dropdown-item-check icon" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M5 12l5 5l10 -10" />
</svg>
</button>
<button class="dropdown-item" type="button" data-bs-value="swift">Swift<svg xmlns="http://www.w3.org/2000/svg" class="dropdown-item-check icon" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M5 12l5 5l10 -10" />
</svg>
</button>
</div>
</div>Sizes
Use .form-select-sm or .form-select-lg on the toggle.
<div class="w-100">
<button class="form-select combobox-toggle form-select-sm" type="button" data-bs-toggle="combobox" data-bs-placeholder="Small select…">
<span class="combobox-value"></span>
</button>
<div class="dropdown-menu">
<button class="dropdown-item" type="button" data-bs-value="1">Option one</button>
<button class="dropdown-item" type="button" data-bs-value="2">Option two</button>
</div>
</div>
<div class="w-100">
<button class="form-select combobox-toggle form-select-lg" type="button" data-bs-toggle="combobox" data-bs-placeholder="Large select…">
<span class="combobox-value"></span>
</button>
<div class="dropdown-menu">
<button class="dropdown-item" type="button" data-bs-value="1">Option one</button>
<button class="dropdown-item" type="button" data-bs-value="2">Option two</button>
</div>
</div>On a <select> the size class is copied to the toggle. The height stays the same with tags and icons in every size.
<div class="w-100">
<select class="form-select form-select-sm" data-bs-toggle="combobox" data-placeholder="Small">
<option value="us" selected data-custom-properties="<span class='flag flag-xs flag-country-us'></span>">United States</option>
<option value="pl" data-custom-properties="<span class='flag flag-xs flag-country-pl'></span>">Poland</option>
<option value="de" data-custom-properties="<span class='flag flag-xs flag-country-de'></span>">Germany</option>
</select>
</div>
<div class="w-100">
<select class="form-select" data-bs-toggle="combobox" data-placeholder="Default">
<option value="us" selected data-custom-properties="<span class='flag flag-xs flag-country-us'></span>">United States</option>
<option value="pl" data-custom-properties="<span class='flag flag-xs flag-country-pl'></span>">Poland</option>
<option value="de" data-custom-properties="<span class='flag flag-xs flag-country-de'></span>">Germany</option>
</select>
</div>
<div class="w-100">
<select class="form-select form-select-lg" data-bs-toggle="combobox" data-placeholder="Large">
<option value="us" selected data-custom-properties="<span class='flag flag-xs flag-country-us'></span>">United States</option>
<option value="pl" data-custom-properties="<span class='flag flag-xs flag-country-pl'></span>">Poland</option>
<option value="de" data-custom-properties="<span class='flag flag-xs flag-country-de'></span>">Germany</option>
</select>
</div>
<div class="w-100">
<select class="form-select form-select-sm" multiple="true" data-bs-toggle="combobox" data-placeholder="Small multiple">
<option value="apple" selected>Apple</option>
<option value="banana" selected>Banana</option>
<option value="cherry" selected>Cherry</option>
<option value="date" selected>Date</option>
<option value="fig">Fig</option>
</select>
</div>
<div class="w-100">
<select class="form-select" multiple="true" data-bs-toggle="combobox" data-placeholder="Default multiple">
<option value="apple" selected>Apple</option>
<option value="banana" selected>Banana</option>
<option value="cherry" selected>Cherry</option>
<option value="date" selected>Date</option>
<option value="fig">Fig</option>
</select>
</div>
<div class="w-100">
<select class="form-select form-select-lg" multiple="true" data-bs-toggle="combobox" data-placeholder="Large multiple">
<option value="apple" selected>Apple</option>
<option value="banana" selected>Banana</option>
<option value="cherry" selected>Cherry</option>
<option value="date" selected>Date</option>
<option value="fig">Fig</option>
</select>
</div>Disabled
Add disabled to the toggle, or to single items.
<div class="w-100">
<button class="form-select combobox-toggle" type="button" data-bs-toggle="combobox" data-bs-placeholder="Cannot interact…" disabled>
<span class="combobox-value"></span>
</button>
<div class="dropdown-menu">
<button class="dropdown-item" type="button" data-bs-value="1">Option one</button>
<button class="dropdown-item" type="button" data-bs-value="2">Option two</button>
</div>
</div>
<div class="w-100">
<button class="form-select combobox-toggle" type="button" data-bs-toggle="combobox" data-bs-placeholder="Some items disabled…">
<span class="combobox-value"></span>
</button>
<div class="dropdown-menu">
<button class="dropdown-item" type="button" data-bs-value="1">Available</button>
<button class="dropdown-item" type="button" data-bs-value="2" disabled>Unavailable</button>
<button class="dropdown-item" type="button" data-bs-value="3">Available</button>
</div>
</div>Native select
Add data-bs-toggle="combobox" to a <select class="form-select"> and the combobox builds the toggle and the menu from its options. The <select> stays in the DOM, keeps its value and fires a normal change event, so forms, validation and your own scripts work as before. This is the mode to use in place of Tom Select.
<div class="w-100">
<label class="form-label" for="combobox-fruit">Fruit</label>
<select class="form-select" id="combobox-fruit" data-bs-toggle="combobox" data-placeholder="Pick a fruit">
<optgroup label="Citrus">
<option value="orange">Orange</option>
<option value="lemon">Lemon</option>
</optgroup>
<optgroup label="Berries">
<option value="strawberry">Strawberry</option>
<option value="blueberry">Blueberry</option>
</optgroup>
</select>
</div><optgroup>becomes a.dropdown-header, anddisabledoptions stay disabled.- The placeholder comes from
data-placeholder, or from the text of an empty<option value="">. - A search field is added automatically. Turn it off with
data-bs-search="false". - Classes such as
.is-invalidand.form-select-smare copied to the toggle. - The toggle follows the
<select>: a form reset,disabled, and its valid or invalid state inside.was-validated. - With a placeholder, the first option is not chosen by default. Mark an option
selected, or setselect.valuebefore the combobox starts, to begin with a value.
Multiple
Add multiple and the picks show as tags. Click a selected item in the menu to remove it. Backspace removes the last tag. There is no limit by default; add data-bs-max-items if you want one.
The tags stay on one line so the field keeps its height. The ones that do not fit are replaced by a +N tag, and clicking it opens the menu. Set data-bs-tags-overflow="wrap" to let the tags wrap onto more lines instead.
<div class="w-100">
<select class="form-select" multiple="true" data-bs-toggle="combobox" data-placeholder="Pick fruits">
<option value="apple" selected>Apple</option>
<option value="banana" selected>Banana</option>
<option value="cherry" selected>Cherry</option>
<option value="date" selected>Date</option>
<option value="elderberry" selected>Elderberry</option>
<option value="fig" selected>Fig</option>
<option value="grape" selected>Grape</option>
<option value="kiwi">Kiwi</option>
<option value="mango">Mango</option>
</select>
</div>Rich options
Put markup in a data-custom-properties attribute to show an avatar, flag or badge next to the option, in the menu and in the toggle.
<div class="w-100">
<select class="form-select" data-bs-toggle="combobox" data-placeholder="Assign to…">
<option value="1" data-custom-properties="<span class='avatar avatar-xs' style='background-image: url(/static/avatars/000m.jpg)'></span>">Paweł Kuna</option>
<option value="2" data-custom-properties="<span class='avatar avatar-xs' style='background-image: url(/static/avatars/001f.jpg)'></span>">Jeffie Lewzey</option>
<option value="3" data-custom-properties="<span class='avatar avatar-xs' style='background-image: url(/static/avatars/002m.jpg)'></span>">Mallory Hulme</option>
</select>
</div>This markup is sanitized before it is added to the page. Tags and attributes outside the allow list, such as <script> or onerror, are removed. Change the list with the allowList option, pass your own sanitizeFn, or set sanitize: false if you trust the markup. These three options work only from JavaScript, not from data attributes.
Menu container
By default the menu sits right after the toggle. Set data-bs-container="body" to append it to the page body, so a card or modal with overflow: hidden cannot clip it.
Changing options from code
After you change the <option>s, select.value, select.disabled or a class such as .is-invalid in a script, call refresh() so the combobox reads them again.
select.append(new Option('Fig', 'fig'))
tabler.Combobox.getInstance(select).refresh()
Moving from Tom Select
| Tom Select | Combobox |
|---|---|
new TomSelect(select) |
data-bs-toggle="combobox" on the <select>, or new tabler.Combobox(select) |
dropdownParent: 'body' |
data-bs-container="body" |
maxItems |
data-bs-max-items |
data-placeholder |
Same attribute |
render.option with data-custom-properties |
data-custom-properties, no render function needed |
onChange |
The native change event on the <select> |
sync() |
refresh() |
create, remote load, other plugins |
Not supported yet |
Examples
Since the items are ordinary HTML, a combobox can show much more than text. On a <select>, put the extra markup in data-custom-properties. In markup mode, wrap it in .dropdown-item-indicator. Either way it is also shown in the toggle once the item is chosen.
Flags
Use the flags plugin for a country picker. The search field finds a country by its name.
<div class="w-100">
<select class="form-select" data-bs-toggle="combobox" data-placeholder="Pick a country" data-bs-search-normalize="true">
<option value="us" data-custom-properties="<span class='flag flag-xs flag-country-us'></span>">United States</option>
<option value="gb" data-custom-properties="<span class='flag flag-xs flag-country-gb'></span>">United Kingdom</option>
<option value="de" data-custom-properties="<span class='flag flag-xs flag-country-de'></span>">Germany</option>
<option value="fr" data-custom-properties="<span class='flag flag-xs flag-country-fr'></span>">France</option>
<option value="pl" data-custom-properties="<span class='flag flag-xs flag-country-pl'></span>">Poland</option>
<option value="es" data-custom-properties="<span class='flag flag-xs flag-country-es'></span>">Spain</option>
<option value="it" data-custom-properties="<span class='flag flag-xs flag-country-it'></span>">Italy</option>
<option value="nl" data-custom-properties="<span class='flag flag-xs flag-country-nl'></span>">Netherlands</option>
<option value="se" data-custom-properties="<span class='flag flag-xs flag-country-se'></span>">Sweden</option>
<option value="jp" data-custom-properties="<span class='flag flag-xs flag-country-jp'></span>">Japan</option>
<option value="br" data-custom-properties="<span class='flag flag-xs flag-country-br'></span>">Brazil</option>
<option value="ca" data-custom-properties="<span class='flag flag-xs flag-country-ca'></span>">Canada</option>
</select>
</div>Payment methods
Use the payments icons to pick a card or a wallet.
<div class="w-100">
<select class="form-select" data-bs-toggle="combobox" data-placeholder="Payment method">
<option value="visa" data-custom-properties="<span class='payment payment-xs payment-provider-visa'></span>" selected>Visa</option>
<option value="mastercard" data-custom-properties="<span class='payment payment-xs payment-provider-mastercard'></span>">Mastercard</option>
<option value="americanexpress" data-custom-properties="<span class='payment payment-xs payment-provider-americanexpress'></span>">American Express</option>
<option value="paypal" data-custom-properties="<span class='payment payment-xs payment-provider-paypal'></span>">PayPal</option>
<option value="stripe" data-custom-properties="<span class='payment payment-xs payment-provider-stripe'></span>">Stripe</option>
<option value="applepay" data-custom-properties="<span class='payment payment-xs payment-provider-applepay'></span>">Apple Pay</option>
</select>
</div>Keyboard shortcuts
Wrap the label in .dropdown-item-label and add a <kbd class="ms-auto"> after it. The shortcut is shown in the toggle too, once the item is chosen.
<div class="w-100">
<button class="form-select combobox-toggle" type="button" data-bs-toggle="combobox" data-bs-placeholder="Choose an action…" data-bs-name="action">
<span class="combobox-value"></span>
</button>
<div class="dropdown-menu">
<button class="dropdown-item" type="button" data-bs-value="cut">
<span class="dropdown-item-label">Cut</span>
<kbd class="ms-auto">ctrl + X</kbd>
</button>
<button class="dropdown-item" type="button" data-bs-value="copy">
<span class="dropdown-item-label">Copy</span>
<kbd class="ms-auto">ctrl + C</kbd>
</button>
<button class="dropdown-item" type="button" data-bs-value="paste">
<span class="dropdown-item-label">Paste</span>
<kbd class="ms-auto">ctrl + V</kbd>
</button>
<button class="dropdown-item" type="button" data-bs-value="all">
<span class="dropdown-item-label">Select all</span>
<kbd class="ms-auto">ctrl + A</kbd>
</button>
<button class="dropdown-item" type="button" data-bs-value="find">
<span class="dropdown-item-label">Find</span>
<kbd class="ms-auto">ctrl + F</kbd>
</button>
<button class="dropdown-item" type="button" data-bs-value="save">
<span class="dropdown-item-label">Save</span>
<kbd class="ms-auto">ctrl + S</kbd>
</button>
</div>
</div>Avatars
Show the person next to the name.
<div class="w-100">
<select class="form-select" data-bs-toggle="combobox" data-placeholder="Assign to…">
<option value="1" data-custom-properties="<span class='avatar avatar-xs' style='background-image: url(/static/avatars/000m.jpg)'></span>">Paweł Kuna</option>
<option value="2" data-custom-properties="<span class='avatar avatar-xs' style='background-image: url(/static/avatars/001f.jpg)'></span>">Jeffie Lewzey</option>
<option value="3" data-custom-properties="<span class='avatar avatar-xs' style='background-image: url(/static/avatars/002m.jpg)'></span>">Mallory Hulme</option>
<option value="4" data-custom-properties="<span class='avatar avatar-xs' style='background-image: url(/static/avatars/003f.jpg)'></span>">Dunn Slane</option>
<option value="5" data-custom-properties="<span class='avatar avatar-xs' style='background-image: url(/static/avatars/004f.jpg)'></span>">Emmy Levet</option>
<option value="6" data-custom-properties="<span class='avatar avatar-xs' style='background-image: url(/static/avatars/005f.jpg)'></span>">Maryjo Lebarree</option>
</select>
</div>Add a name and a role with .dropdown-item-content and .dropdown-item-description.
<div class="w-100">
<button class="form-select combobox-toggle" type="button" data-bs-toggle="combobox" data-bs-placeholder="Select a person…" data-bs-name="person">
<span class="combobox-value"></span>
</button>
<div class="dropdown-menu">
<button class="dropdown-item" type="button" data-bs-value="1">
<span class="dropdown-item-indicator">
<span class="avatar avatar-xs" style="background-image: url(/static/avatars/000m.jpg)"></span>
</span>
<span class="dropdown-item-content">
<span>Paweł Kuna</span>
<small class="dropdown-item-description">Product designer</small>
</span>
<svg xmlns="http://www.w3.org/2000/svg" class="dropdown-item-check icon" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M5 12l5 5l10 -10" />
</svg>
</button>
<button class="dropdown-item" type="button" data-bs-value="2">
<span class="dropdown-item-indicator">
<span class="avatar avatar-xs" style="background-image: url(/static/avatars/001f.jpg)"></span>
</span>
<span class="dropdown-item-content">
<span>Jeffie Lewzey</span>
<small class="dropdown-item-description">Front-end developer</small>
</span>
<svg xmlns="http://www.w3.org/2000/svg" class="dropdown-item-check icon" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M5 12l5 5l10 -10" />
</svg>
</button>
<button class="dropdown-item" type="button" data-bs-value="3">
<span class="dropdown-item-indicator">
<span class="avatar avatar-xs" style="background-image: url(/static/avatars/002m.jpg)"></span>
</span>
<span class="dropdown-item-content">
<span>Mallory Hulme</span>
<small class="dropdown-item-description">Project manager</small>
</span>
<svg xmlns="http://www.w3.org/2000/svg" class="dropdown-item-check icon" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M5 12l5 5l10 -10" />
</svg>
</button>
<button class="dropdown-item" type="button" data-bs-value="4">
<span class="dropdown-item-indicator">
<span class="avatar avatar-xs" style="background-image: url(/static/avatars/003f.jpg)"></span>
</span>
<span class="dropdown-item-content">
<span>Dunn Slane</span>
<small class="dropdown-item-description">QA engineer</small>
</span>
<svg xmlns="http://www.w3.org/2000/svg" class="dropdown-item-check icon" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M5 12l5 5l10 -10" />
</svg>
</button>
</div>
</div>On a multiple <select> the avatars go into the tags, so the field reads as a list of people.
<div class="w-100">
<select class="form-select" data-bs-toggle="combobox" data-placeholder="Add reviewers" multiple="true">
<option value="1" data-custom-properties="<span class='avatar avatar-xs' style='background-image: url(/static/avatars/000m.jpg)'></span>" selected>Paweł Kuna</option>
<option value="2" data-custom-properties="<span class='avatar avatar-xs' style='background-image: url(/static/avatars/001f.jpg)'></span>" selected>Jeffie Lewzey</option>
<option value="3" data-custom-properties="<span class='avatar avatar-xs' style='background-image: url(/static/avatars/002m.jpg)'></span>" selected>Mallory Hulme</option>
<option value="4" data-custom-properties="<span class='avatar avatar-xs' style='background-image: url(/static/avatars/003f.jpg)'></span>" selected>Dunn Slane</option>
<option value="5" data-custom-properties="<span class='avatar avatar-xs' style='background-image: url(/static/avatars/004f.jpg)'></span>" selected>Emmy Levet</option>
<option value="6" data-custom-properties="<span class='avatar avatar-xs' style='background-image: url(/static/avatars/005f.jpg)'></span>">Maryjo Lebarree</option>
</select>
</div>Status
An empty badge works as a status dot.
<div class="w-100">
<button class="form-select combobox-toggle" type="button" data-bs-toggle="combobox" data-bs-placeholder="Set status…">
<span class="combobox-value"></span>
</button>
<div class="dropdown-menu">
<button class="dropdown-item" type="button" data-bs-value="online">
<span class="dropdown-item-indicator">
<span class="badge bg-green"></span>
</span>
<span class="dropdown-item-label">Online</span>
</button>
<button class="dropdown-item" type="button" data-bs-value="away">
<span class="dropdown-item-indicator">
<span class="badge bg-yellow"></span>
</span>
<span class="dropdown-item-label">Away</span>
</button>
<button class="dropdown-item" type="button" data-bs-value="busy">
<span class="dropdown-item-indicator">
<span class="badge bg-red"></span>
</span>
<span class="dropdown-item-label">Busy</span>
</button>
<button class="dropdown-item" type="button" data-bs-value="offline">
<span class="dropdown-item-indicator">
<span class="badge bg-secondary"></span>
</span>
<span class="dropdown-item-label">Offline</span>
</button>
</div>
</div>Logos
Any image works, for example the browser logos.
<div class="w-100">
<select class="form-select" data-bs-toggle="combobox" data-placeholder="Default browser">
<option value="chrome" data-custom-properties="<img src='/static/browsers/chrome.svg' width='20' height='20' alt=''>">Chrome</option>
<option value="firefox" data-custom-properties="<img src='/static/browsers/firefox.svg' width='20' height='20' alt=''>">Firefox</option>
<option value="safari" data-custom-properties="<img src='/static/browsers/safari.svg' width='20' height='20' alt=''>">Safari</option>
<option value="edge" data-custom-properties="<img src='/static/browsers/edge.svg' width='20' height='20' alt=''>">Edge</option>
<option value="opera" data-custom-properties="<img src='/static/browsers/opera.svg' width='20' height='20' alt=''>">Opera</option>
<option value="brave" data-custom-properties="<img src='/static/browsers/brave.svg' width='20' height='20' alt=''>">Brave</option>
</select>
</div>Icons with descriptions
Put an image in .dropdown-item-indicator and a second line in .dropdown-item-description.
<div class="w-100">
<button class="form-select combobox-toggle" type="button" data-bs-toggle="combobox" data-bs-placeholder="Select a currency…" data-bs-name="currency">
<span class="combobox-value"></span>
</button>
<div class="dropdown-menu">
<button class="dropdown-item" type="button" data-bs-value="bitcoin">
<span class="dropdown-item-indicator">
<img src="/static/crypto-currencies/bitcoin.svg" width="20" height="20" alt />
</span>
<span class="dropdown-item-content">
<span>Bitcoin</span>
<small class="dropdown-item-description">BTC</small>
</span>
<svg xmlns="http://www.w3.org/2000/svg" class="dropdown-item-check icon" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M5 12l5 5l10 -10" />
</svg>
</button>
<button class="dropdown-item" type="button" data-bs-value="ethereum">
<span class="dropdown-item-indicator">
<img src="/static/crypto-currencies/ethereum.svg" width="20" height="20" alt />
</span>
<span class="dropdown-item-content">
<span>Ethereum</span>
<small class="dropdown-item-description">ETH</small>
</span>
<svg xmlns="http://www.w3.org/2000/svg" class="dropdown-item-check icon" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M5 12l5 5l10 -10" />
</svg>
</button>
<button class="dropdown-item" type="button" data-bs-value="litecoin">
<span class="dropdown-item-indicator">
<img src="/static/crypto-currencies/litecoin.svg" width="20" height="20" alt />
</span>
<span class="dropdown-item-content">
<span>Litecoin</span>
<small class="dropdown-item-description">LTC</small>
</span>
<svg xmlns="http://www.w3.org/2000/svg" class="dropdown-item-check icon" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M5 12l5 5l10 -10" />
</svg>
</button>
<button class="dropdown-item" type="button" data-bs-value="ripple">
<span class="dropdown-item-indicator">
<img src="/static/crypto-currencies/ripple.svg" width="20" height="20" alt />
</span>
<span class="dropdown-item-content">
<span>Ripple</span>
<small class="dropdown-item-description">XRP</small>
</span>
<svg xmlns="http://www.w3.org/2000/svg" class="dropdown-item-check icon" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M5 12l5 5l10 -10" />
</svg>
</button>
<button class="dropdown-item" type="button" data-bs-value="cardano">
<span class="dropdown-item-indicator">
<img src="/static/crypto-currencies/cardano.svg" width="20" height="20" alt />
</span>
<span class="dropdown-item-content">
<span>Cardano</span>
<small class="dropdown-item-description">ADA</small>
</span>
<svg xmlns="http://www.w3.org/2000/svg" class="dropdown-item-check icon" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M5 12l5 5l10 -10" />
</svg>
</button>
</div>
</div>Badges
Push a badge to the end of the item with .ms-auto, for example to show a count. Like a shortcut, a badge that is a direct child of the item is shown in the toggle too.
<div class="w-100">
<button class="form-select combobox-toggle" type="button" data-bs-toggle="combobox" data-bs-placeholder="Priority…">
<span class="combobox-value"></span>
</button>
<div class="dropdown-menu">
<button class="dropdown-item" type="button" data-bs-value="low">
<span class="dropdown-item-label">Low</span>
<span class="badge bg-blue-lt ms-auto">12</span>
</button>
<button class="dropdown-item" type="button" data-bs-value="medium">
<span class="dropdown-item-label">Medium</span>
<span class="badge bg-yellow-lt ms-auto">5</span>
</button>
<button class="dropdown-item" type="button" data-bs-value="high">
<span class="dropdown-item-label">High</span>
<span class="badge bg-red-lt ms-auto">2</span>
</button>
</div>
</div>Form submission
When data-bs-name is set, a hidden <input> with that name is inserted before the toggle and updated on every change.
<!-- What you write -->
<button class="form-select combobox-toggle" type="button" data-bs-toggle="combobox" data-bs-name="country">…</button>
<!-- What the script adds before the toggle -->
<input type="hidden" name="country" value="us" />
JavaScript
Initialization
The combobox initializes itself on every [data-bs-toggle="combobox"] on page load.
eventActionOnPlugin(Combobox, EVENT_CLICK_DATA_API, `${SELECTOR_DATA_TOGGLE}:not(select)`, 'toggle')
registerPlugin(Combobox, { selector: SELECTOR_DATA_TOGGLE })Via data attributes
| Attribute | Description |
|---|---|
data-bs-toggle="combobox" |
Initializes the combobox on the toggle button. |
data-bs-value |
On a .dropdown-item, the value used when that item is selected. |
Options
Pass options as data-bs-* attributes on the toggle, or as an object when creating the instance.
| Name | Type | Default | Description |
|---|---|---|---|
multiple |
boolean | false |
Allow several items; the menu stays open. |
name |
string | null | null |
Name of the hidden input used for form submission. |
placeholder |
string | '' |
Text shown while nothing is selected. |
search |
boolean | null | null |
false removes the search field on a <select>. Markup mode uses a search input when the menu has one. |
searchPlaceholder |
string | 'Search…' |
Placeholder of the generated search field. |
noResultsText |
string | 'No results found' |
Text of the generated empty message. |
searchNormalize |
boolean | false |
Ignore accents when searching. |
maxItems |
number | null | null |
Most items a multiple select accepts. |
tagsOverflow |
'count' | 'wrap' |
'count' |
How a multiple <select> shows tags that do not fit: a +N tag, or extra lines. |
container |
string | element | null |
Where to append the menu, for example 'body'. |
placement |
string | null | null |
Popper placement; bottom-start (bottom-end in RTL) when empty. |
offset |
array | string | [0, 2] |
Offset of the menu from the toggle. |
boundary |
string | element | 'clippingParents' |
Overflow boundary of the menu. |
sanitize |
boolean | true |
Sanitize the markup from data-custom-properties. |
allowList |
object | Tooltip allow list, plus SVG icons and style on <span> |
Tags and attributes kept by the sanitizer. |
sanitizeFn |
function | null | null |
Your own sanitize function, used in place of the built-in one. |
Methods
| Method | Description |
|---|---|
toggle() |
Opens or closes the menu. |
show() |
Opens the menu. |
hide() |
Closes the menu. |
update() |
Repositions an open menu. |
refresh() |
Rebuilds the menu from the <select> and re-reads its value. |
dispose() |
Removes the instance and the hidden input. |
getInstance(element) |
Static. Returns the instance bound to the element, or null. |
getOrCreateInstance(element, config) |
Static. Returns the existing instance, or creates one. |
Events
Events fire on the toggle button.
| Event | Description |
|---|---|
show.bs.combobox |
Fires when show() is called; can be cancelled. |
shown.bs.combobox |
Fires once the menu is visible. |
hide.bs.combobox |
Fires when hide() is called; can be cancelled. |
hidden.bs.combobox |
Fires once the menu is hidden. |
change.bs.combobox |
Fires when the selection changes. event.value holds the value (an array with multiple) and event.item the clicked item. |
Accessibility
- The toggle gets
role="combobox",aria-haspopup="listbox",aria-expandedandaria-controls, so a screen reader announces the label and the chosen value. The list of items getsrole="listbox"and each itemrole="option"witharia-selected. - A group header is tied to its items with
aria-describedby. - The search field points at the highlighted item with
aria-activedescendant, and the empty message is arole="status"region. - On a
<select>,requiredand.is-invalidare passed to the toggle asaria-requiredandaria-invalid. - Keyboard: ↓ / ↑ open the menu and move between items, Home / End jump to the first or last item, Enter / Space select, Esc closes and returns focus to the toggle, Tab closes. With a search field: the first match is highlighted and Enter selects it, typing on an item continues the search, and ↑ on the first item returns to the search field.
- Label the field with a visible
<label>oraria-label, and give the search input anaria-label.
Class reference
Every class this component ships, grouped by what it changes. A name in braces stands for a family — {color} is any base color, {breakpoint} any responsive step.
combobox-toggle | component | The button that shows the current value; use it together with `.form-select` |
combobox-value | part | Holds the selected label or the placeholder |
combobox-placeholder | part | Added to `.combobox-value` while nothing is selected |
combobox-list | part | Wrapper the script puts around the items; only the list scrolls, the search field stays above it |
combobox-search | part | Sticky wrapper for the search input inside the menu |
combobox-search-input | part | The search field |
combobox-no-results | part | Message shown when the search finds nothing |
dropdown-item-content | part | Column layout for an item with a description |
dropdown-item-description | part | Secondary text under the item label |
dropdown-item-check | part | Check mark shown on the selected item |
CSS
Variables
The component uses local CSS variables for real-time customization. Values for the CSS variables are set via Sass, so Sass customization is still supported, too.
On .combobox-toggle. Source: core/scss/ui/forms/_combobox.scss.
--combobox-menu-max-height: #{$combobox-menu-max-height};
--combobox-placeholder-color: #{$input-placeholder-color};
