Bootstrap Integration

Vanilla Smart Select works perfectly with Bootstrap 5 without CSS conflicts. All classes use the .vs- prefix to avoid collisions.

Compatibility

โœ… Tested with Bootstrap:
  • Bootstrap 5.3.x - Fully compatible
  • Bootstrap 5.2.x - Fully compatible
  • Bootstrap 5.1.x - Fully compatible
๐ŸŽจ Supported Bootstrap Classes:
  • .form-select - Select styling
  • .form-label - Form labels
  • .form-control - Alternative to form-select
  • .is-invalid / .is-valid - Validation states
  • .invalid-feedback - Error messages
  • .mb-3, .mt-3 - Spacing
โœ… Zero Conflicts: All Vanilla Smart Select CSS classes use the .vs- prefix to avoid conflicts with Bootstrap.

File Inclusion Order

๐Ÿ“‹ Recommended Order:
  1. Bootstrap CSS - Load first
  2. Vanilla Smart Select CSS - Load after
  3. Your HTML content
  4. Bootstrap JS (optional - if using Bootstrap components)
  5. Vanilla Smart Select JS
  6. Your JavaScript code

Complete Example

<!DOCTYPE html>
<html lang="en">
<head>
  <!-- Bootstrap CSS -->
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
  
  <!-- Vanilla Smart Select CSS -->
  <link href="vanilla-smart-select.min.css" rel="stylesheet">
</head>
<body>
  <!-- Your content -->
  
  <!-- Bootstrap JS (optional) -->
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
  
  <!-- Vanilla Smart Select JS -->
  <script src="vanilla-smart-select.min.js"></script>
  
  <!-- Your code -->
  <script>
    new VanillaSmartSelect('#mySelect');
  </script>
</body>
</html>

Grid System

Use Bootstrap's grid system normally with Vanilla Smart Select:

View code

HTML

<div class="row">
  <div class="col-md-4">
    <div class="mb-3">
      <label for="grid-select1" class="form-label">Select 1</label>
      <select id="grid-select1" class="form-select">
        <option value="">Select...</option>
        <option value="frontend">๐ŸŽจ Frontend</option>
        <option value="backend">โš™๏ธ Backend</option>
        <option value="mobile">๐Ÿ“ฑ Mobile</option>
        <option value="devops">๐Ÿš€ DevOps</option>
      </select>
    </div>
  </div>
  <div class="col-md-4">
    <div class="mb-3">
      <label for="grid-select2" class="form-label">Select 2</label>
      <select id="grid-select2" class="form-select">
        <option value="">Select...</option>
        <option value="junior">Junior</option>
        <option value="pleno">Mid-level</option>
        <option value="senior">Senior</option>
        <option value="lead">Lead</option>
      </select>
    </div>
  </div>
  <div class="col-md-4">
    <div class="mb-3">
      <label for="grid-select3" class="form-label">Select 3</label>
      <select id="grid-select3" class="form-select">
        <option value="">Select...</option>
        <option value="remoto">๐Ÿ  Remote</option>
        <option value="presencial">๐Ÿฌ On-site</option>
        <option value="hibrido">๐Ÿ”„ Hybrid</option>
      </select>
    </div>
  </div>
</div>

JavaScript

new VanillaSmartSelect('#grid-select1', {
  placeholder: 'Select an area...'
});

new VanillaSmartSelect('#grid-select2', {
  placeholder: 'Select a level...'
});

new VanillaSmartSelect('#grid-select3', {
  placeholder: 'Select a model...'
});

Bootstrap Components

Vanilla Smart Select works perfectly inside Bootstrap components like Cards, Modals, Tabs, etc:

Example with Card

โš™๏ธ Configurations
View code

HTML

<div class="card">
  <div class="card-header">
    โš™๏ธ Configurations
  </div>
  <div class="card-body">
    <div class="mb-3">
      <label for="category-select" class="form-label">Category</label>
      <select id="category-select" class="form-select">
        <option value="">Select...</option>
        <option value="tech">๐Ÿ’ป Technology</option>
        <option value="food">๐Ÿ” Food</option>
        <option value="sports">โšฝ Sports</option>
        <option value="music">๐ŸŽต Music</option>
        <option value="travel">โœˆ๏ธ Travel</option>
      </select>
    </div>
    <div class="mb-3">
      <label for="priority-select" class="form-label">Priority</label>
      <select id="priority-select" class="form-select">
        <option value="">Select...</option>
        <option value="high">๐Ÿ”ด High</option>
        <option value="medium">๐ŸŸก Medium</option>
        <option value="low">๐ŸŸข Low</option>
      </select>
    </div>
  </div>
</div>

JavaScript

new VanillaSmartSelect('#category-select', {
  placeholder: 'Select a category...'
});

new VanillaSmartSelect('#priority-select', {
  placeholder: 'Select priority...'
});

Example with Modal

View code

HTML

<!-- Button to open modal -->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#settingsModal">
  Open Settings
</button>

<!-- Modal -->
<div class="modal fade" id="settingsModal" tabindex="-1" aria-labelledby="settingsModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="settingsModalLabel">Configurations</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        <div class="mb-3">
          <label for="modal-theme" class="form-label">Theme</label>
          <select id="modal-theme" class="form-select">
            <option value="">Select...</option>
            <option value="light">โ˜€๏ธ Light</option>
            <option value="dark">๐ŸŒ™ Dark</option>
            <option value="auto">๐Ÿ”„ Auto</option>
          </select>
        </div>
        <div class="mb-3">
          <label for="modal-language" class="form-label">Language</label>
          <select id="modal-language" class="form-select">
            <option value="">Select...</option>
            <option value="pt">๐Ÿ‡ง๐Ÿ‡ท Portuguรชs</option>
            <option value="en">๐Ÿ‡บ๐Ÿ‡ธ English</option>
            <option value="es">๐Ÿ‡ช๐Ÿ‡ธ Espaรฑol</option>
            <option value="fr">๐Ÿ‡ซ๐Ÿ‡ท Franรงais</option>
          </select>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save</button>
      </div>
    </div>
  </div>
</div>

JavaScript

// Initialize BEFORE the modal opens (show.bs.modal)
const settingsModal = document.getElementById('settingsModal');
let themeSelect, languageSelect;

settingsModal.addEventListener('show.bs.modal', () => {
  if (!themeSelect) {
    themeSelect = new VanillaSmartSelect('#modal-theme', {
      placeholder: 'Select theme...'
    });
  }

  if (!languageSelect) {
    languageSelect = new VanillaSmartSelect('#modal-language', {
      placeholder: 'Select language...',
      searchable: true
    });
  }
});

Single Select with Bootstrap

Basic dropdown with search and placeholder.

View code

HTML

<div class="mb-3">
  <label for="fruits" class="form-label">Select a fruit:</label>
  <select id="fruits" class="form-select">
    <option value="">Select a fruit...</option>
    <option value="maca">๐ŸŽ Apple</option>
    <option value="banana">๐ŸŒ Banana</option>
    <option value="laranja">๐ŸŠ Orange</option>
    <option value="uva">๐Ÿ‡ Grape</option>
    <option value="manga">๐Ÿฅญ Mango</option>
  </select>
</div>

JavaScript

const select = new VanillaSmartSelect('#fruits', {
  searchable: true,
  placeholder: 'Select a fruit...'
});

Multi-Select with Bootstrap

Multiple selection with search integrated into Bootstrap.

View code

HTML

<div class="mb-3">
  <label for="languages" class="form-label">Select languages:</label>
  <select id="languages" class="form-select" multiple>
    <option value="js" selected>JavaScript</option>
    <option value="ts">TypeScript</option>
    <option value="py">Python</option>
    <option value="java">Java</option>
  </select>
</div>

JavaScript

const multiSelect = new VanillaSmartSelect('#languages', {
  searchable: true,
  multiple: true
});

Select with Optgroups

Options organized by groups (optgroup) with Bootstrap.

View code

HTML

<div class="mb-3">
  <label for="countries" class="form-label">Select a country:</label>
  <select id="countries" class="form-select">
    <option value="">Select...</option>
    <optgroup label="South America">
      <option value="br">๐Ÿ‡ง๐Ÿ‡ท Brazil</option>
      <option value="ar">๐Ÿ‡ฆ๐Ÿ‡ท Argentina</option>
    </optgroup>
    <optgroup label="Europe">
      <option value="pt">๐Ÿ‡ต๐Ÿ‡น Portugal</option>
      <option value="es">๐Ÿ‡ช๐Ÿ‡ธ Spain</option>
    </optgroup>
  </select>
</div>

JavaScript

const countriesSelect = new VanillaSmartSelect('#countries', {
  searchable: true
});

Validation with Bootstrap Forms

Perfect integration with Bootstrap form validation.

Please select um departamento.
Please select a role.
View code

HTML

<form id="bootstrap-form" class="needs-validation" novalidate>
  <div class="mb-3">
    <label for="department" class="form-label">Department: *</label>
    <select id="department" class="form-select" required>
      <option value="">Select...</option>
      <option value="ti">๐Ÿ’ป TI</option>
      <option value="rh">๐Ÿ‘ฅ RH</option>
    </select>
    <div class="invalid-feedback">
      Please select a department.
    </div>
  </div>

  <button type="submit" class="btn btn-primary">Submit</button>
</form>

JavaScript

// Initialize selects
new VanillaSmartSelect('#department');
new VanillaSmartSelect('#role');

// Bootstrap Validation
const form = document.getElementById('bootstrap-form');
form.addEventListener('submit', (e) => {
  e.preventDefault();
  
  if (form.checkValidity()) {
    // Valid form
    form.classList.add('was-validated');
    console.log('Form submitted!');
  } else {
    // Show errors
    form.classList.add('was-validated');
  }
});

Clear Button with Bootstrap

Clear button integrated with Bootstrap design.

View code

HTML

<div class="mb-3">
  <label for="colors" class="form-label">Select a color:</label>
  <select id="colors" class="form-select">
    <option value="">Select...</option>
    <option value="vermelho">๐Ÿ”ด Red</option>
    <option value="azul">๐Ÿ”ต Blue</option>
  </select>
</div>

<button id="clear-btn" class="btn btn-outline-secondary">
  Clear Selection
</button>

JavaScript

const colorSelect = new VanillaSmartSelect('#colors', {
  searchable: true,
  allowClear: true
});

// Clear programmatically
document.getElementById('clear-btn').addEventListener('click', () => {
  colorSelect.clear();
});

Themes

Vanilla Smart Select automatically adapts to Bootstrap theme:

  • โœ… Respects Bootstrap CSS variables when available
  • โœ… Classes .form-select and .form-label are preserved
  • โœ… Colors and spacing follow Bootstrap standard
  • โœ… Works with custom Bootstrap themes
  • โœ… Supports Bootstrap light and dark mode
๐Ÿ’ก Tip: If you customized Bootstrap CSS variables (such as primary colors), Vanilla Smart Select will automatically use these colors in focus and hover states.

Known Issues

No known compatibility issues with Bootstrap 5. If you find any, please open an issue.