← All guides BOOTSTRAP 6 · ALPHA 1

Datepicker Examples

Interactive demos, option syntax, and copy-ready snippets for common datepicker patterns.

Based on the official Bootstrap 6 datepicker documentation. This page loads Bootstrap from a CDN, so an internet connection is required.

Before you start

The Bootstrap 6 datepicker is included in the Bootstrap JavaScript bundle together with its datepicker dependency. It uses ES modules, so the script is loaded with type="module". jQuery is not required.

Required CDN includes
<!-- In <head> -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@6.0.0-alpha.1/dist/css/bootstrap.min.css"
      rel="stylesheet">

<!-- Before </body> -->
<script type="module"
  src="https://cdn.jsdelivr.net/npm/bootstrap@6.0.0-alpha.1/dist/js/bootstrap.bundle.min.js">
</script>

The complete HTML file already includes the CDN references and integrity attributes. Keep the matching CSS and JavaScript versions together.

Interactive examples

1Simple datepicker

Click the input and select a date. Use type="text" to avoid the browser's native date picker.

HTML
<label for="simpleDate" class="form-label">Choose a date</label>
<input type="text" class="form-control" id="simpleDate"
       data-bs-toggle="datepicker"
       autocomplete="off" placeholder="Select a date">

2With form field

Place the label, input, helper text, and validation message together in your form layout.

Select the date for your appointment.
Please select a valid date.
HTML
<div class="mb-3">
  <label for="formDate" class="form-label">Appointment date</label>
  <input id="formDate" name="AppointmentDate" type="text"
         class="form-control" data-bs-toggle="datepicker"
         autocomplete="off" placeholder="Choose appointment date">
  <div class="form-text">Select the date for your appointment.</div>
</div>

The datepicker helps select a date; server-side validation is still required when submitting a form.

3With calendar icon

A simple icon placed inside the input wrapper. The wrapper is positioned so the icon stays aligned.

HTML + CSS
<label for="iconDate" class="form-label">Select date</label>
<div class="icon-field">
  <!-- Inline SVG calendar icon -->
  <svg class="calendar-icon" aria-hidden="true">...</svg>
  <input id="iconDate" type="text" class="form-control"
         data-bs-toggle="datepicker" autocomplete="off">
</div>

/* Icon positioning */
.icon-field { position: relative; }
.icon-field svg {
  position: absolute; left: .8rem; top: 50%;
  transform: translateY(-50%); pointer-events: none;
}
.icon-field input { padding-left: 2.5rem; }

4Minimum and maximum dates

Only dates from January 1 through December 31, 2026 are selectable in this example.

HTML
<input type="text" class="form-control" id="minMaxDate"
       data-bs-toggle="datepicker"
       data-bs-date-min="2026-01-01"
       data-bs-date-max="2026-12-31"
       autocomplete="off" placeholder="Select a date in 2026">

date-min and date-max use the YYYY-MM-DD format. Change the values to your required dates.

5Multiple months

Show two months side-by-side. This is especially useful when users need to navigate across month boundaries.

HTML
<input type="text" class="form-control" id="twoMonths"
       data-bs-toggle="datepicker"
       data-bs-selection-mode="multiple-ranged"
       data-bs-display-months-count="2"
       autocomplete="off" placeholder="Select start and end dates">

display-months-count="2" displays two calendar months. Use a larger number if your layout has enough space.

6Date range

Select a start date and an end date. The two example dates below are preselected to demonstrate the syntax.

HTML
<input type="text" class="form-control" id="dateRange"
       data-bs-toggle="datepicker"
       data-bs-selection-mode="multiple-ranged"
       data-bs-selected-dates='["2026-06-10","2026-06-18"]'
       autocomplete="off" placeholder="Select start and end dates">

Remove data-bs-selected-dates if you don't want a preselected range.

7Multi-month date range

Combines range selection and two visible months so users can select dates across months.

HTML
<input type="text" class="form-control" id="multiMonthRange"
       data-bs-toggle="datepicker"
       data-bs-selection-mode="multiple-ranged"
       data-bs-display-months-count="2"
       data-bs-selected-dates='["2026-06-25","2026-07-08"]'
       autocomplete="off" placeholder="Select start and end dates">

8First day of week

Use 0 for Sunday, 1 for Monday, and so on through 6 for Saturday.

HTML
<input type="text" class="form-control" id="weekStart"
       data-bs-toggle="datepicker"
       data-bs-first-weekday="1"
       autocomplete="off" placeholder="Select a date">

For a Sunday-first calendar, change the value to 0.

9Button trigger

Open the calendar from a button, useful for dashboard filters. The display span updates with the selected date.

HTML
<button type="button" class="btn btn-outline-primary"
        data-bs-toggle="datepicker">
  <svg aria-hidden="true">...calendar icon...</svg>
  <span data-bs-datepicker-display>Select date</span>
</button>

For a date range, add data-bs-selection-mode="multiple-ranged" to the button.

10Custom date formatting

Use JavaScript to control the text shown in the input. This example displays dates in a short, readable format.

JavaScript (ES module)
import { Datepicker } from
  "https://cdn.jsdelivr.net/npm/bootstrap@6.0.0-alpha.1/dist/js/bootstrap.bundle.min.js";

const element = document.getElementById("customFormat");

new Datepicker(element, {
  dateFormat: {
    month: "short",
    day: "numeric",
    year: "numeric"
  },
  locale: "en-IN"
});

For example, the selected date can display as Oct 21, 2026. To use a custom formatter, set dateFormat to a function that accepts (date, locale) and returns a string.

Useful attributes and options

Attribute / optionPurposeExample
data-bs-toggle="datepicker"Enables the datepicker.data-bs-toggle="datepicker"
data-bs-date-minEarliest selectable date."2026-01-01"
data-bs-date-maxLatest selectable date."2026-12-31"
data-bs-selection-modeChoose single, multiple, or range selection."multiple-ranged"
data-bs-display-months-countNumber of months shown side-by-side."2"
data-bs-first-weekdayFirst weekday; 0 = Sunday, 1 = Monday."1"
data-bs-selected-datesPreselect one or more dates; for a range, provide start and end.'["2026-06-10","2026-06-18"]'
data-bs-datepicker-displayMarks the text element that displays a button's selected date.<span data-bs-datepicker-display>
dateFormatJavaScript option for custom display formatting.{ month: "short", day: "numeric", year: "numeric" }

JavaScript API: initialize and read selected dates

When you need more control than data attributes provide, import the datepicker class in an ES module and initialize it with options.

import { Datepicker } from
  "https://cdn.jsdelivr.net/npm/bootstrap@6.0.0-alpha.1/dist/js/bootstrap.bundle.min.js";

const input = document.getElementById("myDatepicker");

const picker = new Datepicker(input, {
  selectionMode: "single",
  firstWeekday: 1
});

// Read selected dates (YYYY-MM-DD strings)
console.log(picker.getSelectedDates());

// Listen for a selection change
input.addEventListener("change.bs.datepicker", (event) => {
  console.log("Selected dates:", event.dates);
});

Bootstrap 6 uses ES modules; unlike Bootstrap 5, it does not expose the old window.bootstrap global. Avoid examples that rely on bootstrap.Datepicker being globally available when using the CDN build.