Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
C

Choices

> 编程语言
Open source

A vanilla JS customisable select box/text input plugin ⚡️

6.8K stars0 likes2 views
WebsiteGitHub

About

A vanilla JS customisable select box/text input plugin ⚡️

Choices.js

A vanilla, lightweight (~20kb gzipped ), configurable select box/text input plugin. Similar to Select2 and Selectize but without the jQuery dependency.

Demo

TL;DR

  • Lightweight
  • No jQuery dependency
  • Configurable sorting
  • Flexible styling
  • Fast search/filtering
  • Clean API
  • Right-to-left support
  • Custom templates

Interested in writing your own ES6 JavaScript plugins? Check out ES6.io for great tutorials!

Sponsored by:


Table of Contents

  • Installation
  • Setup
  • Terminology
  • Input Types
  • Configuration Options
  • Callbacks
  • Events
  • Methods
  • CSS custom properties
  • Development
  • License

Installation

With NPM:

bash
npm install choices.js

With Yarn:

bash
yarn add choices.js

From a CDN:

Notes:

  • There is sometimes a delay before the latest version of Choices is reflected on the CDN.
  • Examples below pin a version (v11.1.0). Check latest release and update v11.1.0 to the latest tag before using.
…

Or include Choices directly:

xml

<link rel="stylesheet" href="public/assets/styles/base.min.css" />

<link rel="stylesheet" href="public/assets/styles/choices.min.css" />

<script src="/public/assets/scripts/choices.min.js"></script>

CSS/SCSS

The use of import of css/scss is supported from webpack.

In .scss:

scss
@import "choices.js/src/styles/choices";

In .js/.ts:

javascript
import "choices.js/public/assets/styles/choices.css";

Setup

Note: If you pass a selector which targets multiple elements, the first matching element will be used. Versions prior to 8.x.x would return multiple Choices instances.

…

Terminology

Word Definition
Choice A choice is a value a user can select. A choice would be equivalent to the <option></option> element within a select input.
Group A group is a collection of choices. A group should be seen as equivalent to a <optgroup></optgroup> element within a select input.
Item An item is an inputted value (text input) or a selected choice (select element). In the context of a select element, an item is equivalent to a selected option element: <option value="Hello" selected></option> whereas in the context of a text input an item is equivalent to <input type="text" value="Hello">

Input Types

Choices works with the following input types, referenced in the documentation as noted.

HTML Element Documentation "Input Type"
<input type="text"> text
<select> select-one
<select multiple> select-multiple

Configuration Options

silent

Type: Boolean Default: false

Input types affected: text, select-one, select-multiple

Usage: Optionally suppress console errors and warnings.

items

Type: Array Default: []

Input types affected: text

Usage: Add pre-selected items (see terminology) to text input.

Pass an array of strings:

['value 1', 'value 2', 'value 3']

Pass an array of objects:

[{
  value: 'Value 1',
  label: 'Label 1',
  id: 1
},
{
  value: 'Value 2',
  label: 'Label 2',
  id: 2,
  customProperties: {
    random: 'I am a custom property'
  }
}]

choices

Type: Array Default: []

Input types affected: select-one, select-multiple

Usage: Add choices (see terminology) to select input.

Pass an array of objects:

…

renderChoiceLimit

Type: Number Default: -1

Input types affected: select-one, select-multiple

Usage: The amount of choices to be rendered within the dropdown list ("-1" indicates no limit). This is useful if you have a lot of choices where it is easier for a user to use the search area to find a choice.

maxItemCount

Type: Number Default: -1

Input types affected: text, select-multiple

Usage: The amount of items a user can input/select ("-1" indicates no limit).

closeDropdownOnSelect

Type: Boolean | 'auto' Default: auto

Input types affected: select-one, select-multiple

Usage: Control how the dropdown closes after making a selection for select-one or select-multiple.

  • 'auto' defaults based on backing-element type:
  • select-one: true
  • select-multiple: false

singleModeForMultiSelect

Type: Boolean Default: false

Input types affected: select-one, select-multiple

Usage: Make select-multiple with a max item count of 1 work similar to select-one does. Selecting an item will auto-close the dropdown and swap any existing item for the just selected choice. If applied to a select-one, it functions as above and not the standard select-one.

addChoices

Type: Boolean Default: false

Input types affected: select-multiple, select-one

Usage: Whether a user can add choices dynamically.

Note: addItems must also be true

addItems

Type: Boolean Default: true

Input types affected: text

Usage: Whether a user can add items.

removeItems

Type: Boolean Default: true

Input types affected: text, select-multiple

Usage: Whether a user can remove items.

removeItemButton

Type: Boolean Default: false

Input types affected: text, select-one, select-multiple

Usage: Whether each item should have a remove button.

removeItemButtonAlignLeft

Type: Boolean Default: false

Input types affected: text, select-one, select-multiple

Usage: Align item remove button left vs right

editItems

Type: Boolean Default: false

Input types affected: text

Usage: Whether a user can edit items. An item's value can be edited by pressing the backspace.

allowHTML

Type: Boolean Default: false

Input types affected: text, select-one, select-multiple

Usage: Whether HTML should be rendered in all Choices elements. If false, all elements (placeholder, items, etc.) will be treated as plain text. If true, this can be used to perform XSS scripting attacks if you load choices from a remote source.

allowHtmlUserInput

Type: Boolean Default: false

Input types affected: text, select-one, select-multiple

Usage: Whether HTML should be escaped on input when addItems or addChoices is true. If false, user input will be treated as plain text. If true, this can be used to perform XSS scripting attacks if you load choices from a remote source.

duplicateItemsAllowed

Type: Boolean Default: true

Input types affected: text, select-multiple, select-one

Usage: Whether duplicate inputted/chosen items are allowed

delimiter

Type: String Default: ,

Input types affected: text

Usage: What divides each value. The default delimiter separates each value with a comma: "Value 1, Value 2, Value 3".

paste

Type: Boolean Default: true

Input types affected: text, select-multiple

Usage: Whether a user can paste into the input.

searchEnabled

Type: Boolean Default: true

Input types affected: select-one, select-multiple

Usage: Whether a search area should be shown.

searchChoices

Type: Boolean Default: true

Input types affected: select-one

Usage: Whether choices should be filtered by input or not. If false, the search event will still emit, but choices will not be filtered.

searchDisabledChoices

Type: Boolean Default: false

Input types affected: select-one, select-multiple

Usage: Whether disabled choices should be included in search results. If true, disabled choices will appear in search results but still cannot be selected. This is useful when you want users to see what options exist but are currently unavailable. Placeholders are always excluded from search results regardless of this setting.

searchFields

Type: Array/String Default: ['label', 'value']

Input types affected:select-one, select-multiple

Usage: Specify which fields should be used when a user is searching. If you have added custom properties to your choices, you can add these values thus: ['label', 'value', 'customProperties.example'].

searchFloor

Type: Number Default: 1

Input types affected: select-one, select-multiple

Usage: The minimum length a search value should be before choices are searched.

searchResultLimit: 4,

Type: Number Default: 4

Input types affected: select-one, select-multiple

Usage: The maximum amount of search results to show ("-1" indicates no limit).

shadowRoot

Type: Document Element Default: null

Input types affected: select-one, select-multiple

Usage: You can pass along the shadowRoot from your application like so.

javascript
var shadowRoot = document
  .getElementById('wrapper')
  .attachShadow({ mode: 'open' });
...
var el = shadowRoot.querySelector(...);
var choices = new Choices(el, {
  shadowRoot: shadowRoot,
});

position

Type: String Default: auto

Input types affected: select-one, select-multiple

Usage: Whether the dropdown should appear above (top) or below (bottom) the input. By default, if there is not enough space within the window the dropdown will appear above the input, otherwise below it.

resetScrollPosition

Type: Boolean Default: true

Input types affected: select-multiple

Usage: Whether the scroll position should reset after adding an item.

addItemFilter

Type: `string | RegExp |

Issues· 186 open

View all issuesOpen on GitHub
  • #1298

    [BUG] alt+tab breaks focus

    bugUpdated Sep 13, 2026
  • #1431

    F5 and browser reload shortcuts briefly open a focused closed select

    Updated Aug 26, 2026
  • #1427

    [Feature Request] Add `tabIndex` option to configure `tabindex` on the outer container or input

    feature requestUpdated Jul 29, 2026
  • #1424

    CSS for multi-selects uses opacity var, single-selects doesn't

    bugUpdated Jul 22, 2026
  • #1416

    Select does not work with VoiceOver

    bugUpdated Jul 15, 2026
  • #1223

    Show groupHeading when searching/filtering

    feature requestUpdated Jul 13, 2026
  • #1370

    Expose Fuse to be used independently

    help wantedfeature requestgood first issueUpdated May 25, 2026
  • #1408

    Simple single-input mode

    feature requestUpdated May 25, 2026
  • #1407

    Combobox behavior

    feature requestUpdated May 25, 2026
  • #1405

    Dropdown always scrolls to selected item on open, hiding options above it (regression from v10)

    bugUpdated May 21, 2026

> Tags

JavaScriptchoicechoiceschoicesjsdropdown-menus

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 23, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言