Skip to content

Installation

DotSelect can be installed via npm, loaded from a CDN, or imported as an ES module.

npm

bash
npm install dot-select

Then import it in your project:

js
import DotSelect from 'dot-select';
import 'dot-select/dist/css/dot-select.min.css';

TIP

If you are using a bundler like Vite, Webpack, or Rollup, the CSS import will be handled automatically.

CDN (jsDelivr)

Add the stylesheet and script to your HTML:

html
<!-- CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/dot-select@latest/dist/css/dot-select.min.css">

<!-- JavaScript -->
<script src="https://cdn.jsdelivr.net/npm/dot-select@latest/dist/dot-select.min.js"></script>

For production, pin to a specific version:

html
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/dot-select@1.0.7/dist/css/dot-select.min.css">
<script src="https://cdn.jsdelivr.net/npm/dot-select@1.0.7/dist/dot-select.min.js"></script>

With a Theme

To use a specific theme, replace the default CSS with the theme CSS:

html
<!-- Bootstrap 5 theme -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/dot-select@latest/dist/css/themes/bootstrap5.min.css">

<!-- Tailwind theme -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/dot-select@latest/dist/css/themes/tailwind.min.css">

ES Module Import

For modern browsers that support ES modules:

html
<script type="module">
  import DotSelect from 'https://cdn.jsdelivr.net/npm/dot-select@latest/dist/esm/dot-select.min.mjs';

  // DotSelect auto-initializes elements with data-dot-select
  // Or manually initialize:
  DotSelect.init();
</script>

Manual Initialization

By default, DotSelect auto-initializes all <select data-dot-select> elements when the DOM is ready. You can disable this and initialize manually:

html
<script src="https://cdn.jsdelivr.net/npm/dot-select@latest/dist/dot-select.min.js"
        data-dot-select-auto-init="false"></script>

<script>
  // Initialize all dot-select elements
  DotSelect.init();

  // Or initialize a specific element
  const select = document.querySelector('#my-select');
  const instance = new DotSelect(select);
</script>

Including Plugins

Plugins are included in the main bundle. Activate them via the data-plugins attribute:

Or register custom plugins via JavaScript:

js
import DotSelect from 'dot-select';
import { myPlugin } from './my-plugin';

DotSelect.plugin('my-plugin', myPlugin);

Including Locales

Locales are bundled with DotSelect. Set the language via the data-locale attribute:

Or register a custom locale:

js
DotSelect.registerLocale('custom', {
  noResults: 'Nothing found',
  searching: 'Looking...',
  loadMore: 'Show more results',
  addItem: 'Add "{@term}"',
});

Verifying Installation

After installation, open your browser console and check:

js
console.log(DotSelect.version); // e.g., "1.0.0"

Or verify that a select element has been initialized:

js
const instance = DotSelect.getInstance(document.querySelector('#my-select'));
console.log(instance); // DotSelect instance or null

WARNING

Make sure the CSS file is loaded before the JavaScript file to prevent a flash of unstyled content (FOUC).

MIT Licensed