Select2 v4 theme for Bootstrap4

  • By Takashi Kanemoto
  • Last update: Jan 3, 2023
  • Comments: 16


npm version npm Packagist Version Packagist Downloads

Select2 v4 theme for Bootstrap4 (Compatible to boostrap 4.0.0+)

Live demo




<link rel="stylesheet" href="/path/to/select2.css">
<link rel="stylesheet" href="[email protected]/dist/select2-bootstrap4.min.css">


# npm
$ npm install @ttskch/select2-bootstrap4-theme

# yarn
$ yarn add @ttskch/select2-bootstrap4-theme

# composer
$ composer require ttskch/select2-bootstrap4-theme
<link rel="stylesheet" href="/path/to/select2.css">
<link rel="stylesheet" href="/path/to/select2-bootstrap4.min.css">


    theme: 'bootstrap4',

Getting involved

  1. Fix src/_layout.scss, src/_single.scss or src/_multiple.scss
  2. Do npm run build:both
  3. Send me a Pull Request

You can use docs dir for your development.

  1. Do npm run prepare (this creates symlink to dist/select2-bootstrap4.css onto docs)
  2. Serve docs with your local web server (e.g. php -S localhost:8888 -t docs)
  3. Do npm run watch
  4. Tweak scss and browse demo page on your browser



  • 1

    Improve style

    Contains changes (some are opinionated) for better integration with Bootstrap 4

    Add stylelint

    • Same configuration as Boostrap
    • Allows BEM-like selectors
    • Some rules have been disabled ad-hoc

    Move layout to its own partial

    Allow users to customize individual components or to use just one of them (e.g., "single" and "layout" when "multiple" is not needed)

    Improve single component

    • Lint style
    • Use $input-color to match Bootstrap
    • Use $input-padding-x to match Bootstrap
    • Use $input-placeholder-color to match Bootstrap

    Improve multiple component

    • Lint style
    • Use $input-padding-x to match Bootstrap
    • Use $input-color to match Bootstrap

    Improve layout partial

    • Lint style
    • Use border-bottom-radius mixin
    • Fix border radius on open containers
    • Use color-yiq mixin to pick the correct color in highlighted choice
    • Use $input-padding-y and $input-padding-x
    • Use $input-bg as base color to darken for selected choice

    Fix cursor on disabled elements

    Reproducible with Chrome 88 on macOS





  • 2

    Bootstrap variable file should not be introduced in layout.css

    If I use gulp-sass instead of sass-loader to compile SCSS source code, I will not be able to proceed.

    I think it is better to add in webpack.config.js:

        loader: 'sass-loader',
        options: {
            prependData: `
                @import "~bootstrap/scss/functions";
                @import "~bootstrap/scss/variables";
                @import "~bootstrap/scss/mixins";
  • 3

    Clear button x is not centered.

    /* Fix for select2-bootstrap4-theme clear buttons on dropdowns */
    .select2-container--bootstrap4 .select2-selection__clear {
        line-height: .95em;
        padding-left: 0.26em;
  • 4

    Styling of dropdown icon does not match BS4 default

    The icon is a down triangle instead of a down chevron... I tweaked your demo page using the browser console to show the problem:

  • 5

    Use custom-select-% variable instead of input

    is there a reason why this package uses the input field variable instead of the custom-select-% variables?

    I had a custom drop-down indicator on my normal select fields but when I installed this package, I lost that customization. Looking through your source code, it doesnt look like any of these variables are used.

    Is there a particular reason for this?

  • 6

    Get the primary theme colour properly

    Using the bootstrap function to get the theme colour means that the source can be used by people who have overridden the primary theme colour by setting it in $theme-colours as per bootstrap docs

    Fixes #46

  • 7

    Code proposal for "border-radius"

    If in the Bootstrap variable file we disable the rounded border, the theme does not reflect this option.

  • 8

    Prepend multiselect breaks when you go onto a second line.

    As seen in the image below when you have a multi select and a prepend, if your selects go onto a second line it causes the entire box to drop onto the next line instead of growing on the same line.


    <!DOCTYPE html>
      <!-- bootstrap -->
      <link rel="stylesheet" href="" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
      <!-- select2 -->
      <link href="" rel="stylesheet" />
      <!-- select2-bootstrap4-theme -->
      <link href="" rel="stylesheet"> <!-- for live demo page -->
      <link href="select2-bootstrap4.css" rel="stylesheet"> <!-- for local development env -->
    <body class="pt-5" style="min-height:90vh">
    <div class="container">
      <h3>Example of <a href="" target="_blank">@ttskch/select2-bootstrap4-theme</a></h3>
        <div class="form-group">
          <label>Example of multiple select</label>
              <div class="input-group">
          <div class="input-group-prepend">
            <span class="input-group-text">Prepend</span>
          <select multiple placeholder="Choose anything" data-allow-clear="1">
    <!-- bootstrap -->
    <script src="" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
    <script src="" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
    <!-- select2 -->
    <script src=""></script>
    <!-- select2-bootstrap4-theme -->
    $(function () {
      $('select').each(function () {
          theme: 'bootstrap4',
          width: 'style',
          placeholder: $(this).attr('placeholder'),
          allowClear: Boolean($(this).data('allow-clear')),
  • 9

    Match style of text input box a bit more

    • Add a background to ensure itโ€™s readable if placed on a dark background
    • Use border-radius/box-shadow/transition mixins

    The unrelated height calc changes are due to

  • 10

    Fix form-control layout

    The input field does not use the full size of the fieldset, with this change it fits the column fully. Also the select2 option "width" must be set to "style", otherwise the calculation makes it go beyond the fieldset.

  • 11

    BS Theme not working on js-example-tags

    The theme doesn't seem to be working on the tags element. This is the code I am using below. But the image shows the differance between the Select2 field and the BS4 field

    <link href="[email protected]/dist/css/select2.css" rel="stylesheet" />
    <link rel="stylesheet" href="../css/select2-bootstrap4.css" type="text/css" />
    <select class="form-control js-example-tags" name="caller" autofocus>
    <option>Pit Lane</option>
    theme: 'bootstrap4',
    tags: true


  • 12

    Deprecation warnings

    The sass builder gives deprecation warnings when building this package. I fixed these warnings, but node-sass doesn't compile the code anymore. Since node-sass is deprecated (, I swapped it out for sass. This changed a lot of lines in the dist directory, but these are all just curly brackets that are placed on it's own line.

  • 13

    Deprecation Warnings

    When running npm build on a repository that depends on this, I get a lot of deprecation warnings due to SCSS that does math without encompassing it in the calc() function. Is a fix for this in the works? If not I would be happy to work on one and make a PR when I have the time, just let me know! :)

  • 14

    Fix search field background color.

    Fix select2-search__field background color by changing to transparent like default and classic themes.

    Currently when the Bootstrap's $input-bg variable isn't white, the search field still white and looks like this: image

  • 15

    Invalid layout on multiple select and input-group

    When using select2 with multi select, input-group and the total length of items is smaller than the form group, the prepend and append groups are aligned correctly:


    But if more items are added, the prepend and append groups move to a new line:


  • 16

    Select2 Multiple Tagging Support

    Is this theme support for select2 multiple tagging?

    The default style is like this: image

    But when I applied the theme:

    $('.tagging').select2({theme: 'bootstrap4', tags: true});

    The style is ugly:


    Is there any instruction for this or it's not available?