An always-visible Bootstrap 6 Datepicker for a consultation booking page. The inline calendar marks a preselected day, closed weekends and fully booked dates in three distinct styles. Picking a day fills a panel of start times beside it. It suits appointment, clinic and demo-call booking pages.
How it works
The calendar is a plain <div class="icd-cal" data-bs-toggle="datepicker" data-bs-inline="true">. script.js imports Datepicker from the Bootstrap 6 bundle and creates the inline instance itself, so it can pass Vanilla Calendar Pro options through vcpOptions:
disableDatesPastanddateMin(tomorrow) block today and earlier.dateMaxcomes fromdata-icd-max-days.disableWeekdaysusesCLOSED_WEEKDAYS(Saturday and Sunday).disableDateslists the fully booked days. They are built from the day offsets indata-icd-booked, so the sample never shows stale dates.onCreateDateElsadds.icd-bookedto those cells, so CSS can draw them in pink with a strikethrough, while closed weekends get a grey tile.styles.calendaris set tovc icd-cal, because Vanilla Calendar Pro replaces the class list of the element it renders into.
selectedDates preselects the first open, not fully booked weekday from two days ahead. The change.bs.datepicker event passes the chosen date to renderTimes(). It writes the ISO date into the hidden .icd-date-value input (kept outside the calendar, which replaces its own HTML), prints the date in .icd-day and builds .btn-check radios from TIMES. Times returned by takenTimes() are disabled. Clicking the selected day again deselects it and shows the .icd-empty hint. Confirming simulates a request, marks that time as taken and shows the .icd-done alert.
Customization
data-icd-bookedon.icd-root: comma-separated day offsets from today that are fully booked, e.g.1,4,8,11.data-icd-max-dayson.icd-root: how far ahead visitors can book (60 days by default).CLOSED_WEEKDAYSandTIMESinscript.js: opening days and the start times offered.- Replace
takenTimes()with data from your API, and thesetTimeoutin the submit handler with afetch()POST. --icd-plum,--icd-bookedand--icd-blushon.icd-root: accent, booked-day and background colors. The calendar reads them through--bs-datepicker-day-selected-bgand the other variables on.icd-cal.
Use cases
- Consultation booking: an always-visible calendar shows available days with weekends closed
- Service and clinic sites: fully booked days are disabled and a preselected date saves a click
- Scheduling pages: time slots for the chosen day appear next to the calendar
- Sales and demo requests: visitors pick a day and a slot without opening a popup
Accessibility
Vanilla Calendar Pro renders date cells as a grid with role="gridcell", aria-selected and aria-current="date", and disabled days cannot be focused. The calendar wrapper is a labelled group, and the legend explains the colors in text, so color is not the only cue. Booked days also use a strikethrough. Time choices are native radio buttons in a fieldset with a hidden legend, so arrow keys move between them, and taken times are disabled. The selected day heading and the success alert are live regions.
Bootstrap 6 notes
Bootstrap 5 had no calendar, so this needed a plugin. Bootstrap 6 adds Datepicker with an inline mode (data-bs-inline="true") and passes extra calendar options through vcpOptions. Radio buttons styled as buttons are <label class="btn-check btn-outline theme-primary"> with the input inside, avatars use the new .avatar class, and alerts are alert theme-success. Built on 6.0.0-alpha.1, so the Datepicker API may still change. Icons come from Bootstrap Icons.