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:
- Bootstrap CSS - Load first
- Vanilla Smart Select CSS - Load after
- Your HTML content
- Bootstrap JS (optional - if using Bootstrap components)
- Vanilla Smart Select JS
- 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.
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-selectand.form-labelare 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.