TExcelTAD
Home › Bootstrap › BS5 Select Menus

Bootstrap 5 Select Menus

A <select> lets users pick from a list of options. Browsers draw selects very differently, so Bootstrap gives them a custom look with the .form-select class: consistent padding, border and a custom arrow icon, while keeping the native dropdown list (which works well on phones).

Basic select

html · try it yourself
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
  <label for="country" class="form-label">Country</label>
  <select class="form-select" id="country">
    <option selected disabled value="">Choose…</option>
    <option value="vn">🇻🇳 Vietnam</option>
    <option value="jp">🇯🇵 Japan</option>
    <option value="br">🇧🇷 Brazil</option>
    <option value="ca">🇨🇦 Canada</option>
  </select>
  <p class="mt-2 small" id="out">Nothing chosen yet.</p>
  <script>
    document.getElementById('country').addEventListener('change', (e) => {
      const text = e.target.selectedOptions[0].textContent;
      document.getElementById('out').textContent = 'You chose ' + text;
      console.log('value =', e.target.value);
    });
  </script>
</body>
</html>

A first option that is disabled and selected with an empty value acts as a placeholder — users can't pick it again once they've chosen something.

Sizes, multiple and size

html · try it yourself
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
  <select class="form-select form-select-lg mb-2" aria-label="Large select"><option>Large select</option></select>
  <select class="form-select form-select-sm mb-2" aria-label="Small select"><option>Small select</option></select>
  <select class="form-select mb-2" aria-label="Disabled select" disabled><option>Disabled</option></select>
  <label for="skills" class="form-label small mb-1">Skills (hold Ctrl/⌘ to pick several)</label>
  <select class="form-select" id="skills" multiple size="3">
    <option>HTML</option>
    <option selected>CSS</option>
    <option>JavaScript</option>
    <option selected>Bootstrap</option>
  </select>
  <script>
    const s = document.getElementById('skills');
    const show = () => console.log('selected:', [...s.selectedOptions].map((o) => o.text).join(', '));
    s.addEventListener('change', show);
    show();
  </script>
</body>
</html>

The multiple attribute allows several choices and shows the list as a box; size sets how many rows are visible.

Grouping options

<optgroup> creates labelled, non-selectable group headings inside the list.

html · try it yourself
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
  <label for="course" class="form-label">Pick a course</label>
  <select class="form-select" id="course">
    <optgroup label="Web Development">
      <option>HTML</option>
      <option>CSS</option>
      <option selected>Bootstrap</option>
    </optgroup>
    <optgroup label="Programming Languages">
      <option>Python</option>
      <option>Rust</option>
    </optgroup>
  </select>
</body>
</html>

Selects in layouts

Selects work in grids, inline forms and input groups just like text inputs. A common pattern is a filter bar:

html · try it yourself
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
  <form class="row g-2 align-items-end" id="filters">
    <div class="col-6 col-md-4">
      <label class="form-label small" for="cat">Category</label>
      <select class="form-select form-select-sm" id="cat"><option>All</option><option>Books</option><option>Games</option></select>
    </div>
    <div class="col-6 col-md-4">
      <label class="form-label small" for="sort">Sort by</label>
      <select class="form-select form-select-sm" id="sort"><option>Newest</option><option>Price ↑</option><option>Price ↓</option></select>
    </div>
    <div class="col-12 col-md-4 d-grid">
      <button class="btn btn-sm btn-primary" type="submit">Apply</button>
    </div>
  </form>
  <script>
    document.getElementById('filters').addEventListener('submit', (e) => {
      e.preventDefault();
      console.log('category:', document.getElementById('cat').value, '| sort:', document.getElementById('sort').value);
    });
  </script>
</body>
</html>

Class reference

Class / attribute Effect
.form-select Styled select (required)
.form-select-lg / .form-select-sm Size
multiple Allow several selections
size="n" Show n rows as a list box
disabled Disable the whole select (or one <option>)
<optgroup label="…"> Option group heading

Note: Don't use .form-control on a <select>. Since Bootstrap 5, selects have their own class, .form-select, which adds the custom arrow.

Test yourself

Which class styles a <select> in Bootstrap 5?

  1. .form-control
  2. .form-select
  3. .custom-select
  4. .select

Which attribute allows choosing several options?

  1. size
  2. multiple
  3. data-bs-multi
  4. selected

What does <optgroup> do?

  1. Creates a selectable option
  2. Adds a labelled, non-selectable group of options
  3. Makes the select larger
  4. Adds a search box