Snippets Datepicker

Bootstrap 5 Custom Date Picker with Calendar Popover

A custom date picker with a popover month calendar, today and clear shortcuts, past days disabled and keyboard-friendly buttons.

Bootstrap 5 No jQuery Jul 2020 2.2K views

<section class="wdw-stage">
  <div class="container" style="max-width:460px">
    <div class="text-center mb-4">
      <span class="wdw-eyebrow">Booking</span>
      <h2 class="wdw-heading h2 mt-1 mb-2">Pick a date</h2>
      <p class="wdw-muted mb-0">Choose the day for your appointment.</p>
    </div>
    <form class="wdw-card p-4" id="dpForm" novalidate>
      <label for="dpInput" class="form-label fw-semibold">Appointment date</label>
      <div class="dp position-relative" id="dp">
        <div class="input-group">
          <input type="text" class="form-control" id="dpInput" placeholder="Select a date" readonly aria-haspopup="dialog" aria-expanded="false" aria-controls="dpPanel">
          <button type="button" class="btn btn-outline-secondary" id="dpToggle" aria-label="Open calendar">
            <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="5" width="18" height="16" rx="3"/><path d="M8 3v4M16 3v4M3 10h18"/></svg>
          </button>
        </div>
        <div class="dp-panel wdw-card-sm p-3" id="dpPanel" role="dialog" aria-label="Choose date" hidden>
          <div class="d-flex align-items-center justify-content-between mb-2">
            <button type="button" class="btn btn-sm bg-body-secondary text-body rounded-circle dp-nav" data-dp="-1" aria-label="Previous month"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M15 6l-6 6 6 6"/></svg></button>
            <strong id="dpTitle" aria-live="polite"></strong>
            <button type="button" class="btn btn-sm bg-body-secondary text-body rounded-circle dp-nav" data-dp="1" aria-label="Next month"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 6l6 6-6 6"/></svg></button>
          </div>
          <div class="dp-grid dp-week text-center small wdw-muted" aria-hidden="true"><span>Su</span><span>Mo</span><span>Tu</span><span>We</span><span>Th</span><span>Fr</span><span>Sa</span></div>
          <div id="dpDays" role="grid" aria-labelledby="dpTitle"></div>
          <div class="d-flex justify-content-between mt-2">
            <button type="button" class="btn btn-sm btn-link text-decoration-none" id="dpToday">Today</button>
            <button type="button" class="btn btn-sm btn-link text-decoration-none link-secondary" id="dpClear">Clear</button>
          </div>
        </div>
      </div>
      <div class="form-text" id="dpHelp">Pick any day from today onwards. Open the calendar and use the arrow keys to move between days.</div>
      <button type="submit" class="btn btn-primary rounded-pill w-100 mt-4">Confirm date</button>
      <div class="alert alert-success mt-3 mb-0 py-2" id="dpResult" role="status" hidden></div>
    </form>
  </div>
</section>

Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.

Free to use in personal and commercial projects under the MIT license.