flatpickr-ce: Date Range & Time Picker for Vanilla JS

Category: Date & Time , Javascript | November 12, 2026
Authorcolinli007
Last UpdateNovember 12, 2026
LicenseMIT
Views0 views
flatpickr-ce: Date Range & Time Picker for Vanilla JS

flatpickr-ce is the upgraded version of flatpickr for date and time inputs in vanilla JavaScript.

It preserves flatpickr’s API, themes, and plugins, and adds year-only selection alongside fixes for keyboard focus, mobile inputs, and localized dates.

Features

  • Single-date, multiple-date, date-range, and time-only modes.
  • Date limits and custom functions for enabling or disabling dates.
  • Locale-aware calendar labels and customizable date formats.
  • Inline calendars, week numbers, and multi-month views.
  • Week, month, year, and paired-input range plugins.
  • Dark, light, Airbnb, confetti, and Material themes.

How to Use flatpickr-ce

Load flatpickr-ce from a CDN

<!-- Core Stylesheet -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr-ce/dist/flatpickr.min.css">
<!-- OPTIONAL THEMES -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr-ce/dist/light.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr-ce/dist/dark.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr-ce/dist/airbnb.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr-ce/dist/confetti.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr-ce/dist/material_blue.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr-ce/dist/material_green.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr-ce/dist/material_red.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr-ce/dist/material_orange.min.css">
<input id="event-date" name="event_date" type="text" placeholder="Choose a date">
<!-- Core JavaScript -->
<script src="https://cdn.jsdelivr.net/npm/flatpickr-ce/dist/flatpickr.min.js"></script>
<!-- OPTIONAL LOCALS -->
<script src="https://cdn.jsdelivr.net/npm/flatpickr-ce/dist/l10n/fr.js"></script>
....
<script>
  flatpickr("#event-date", {
    minDate: "today",
    dateFormat: "Y-m-d",
    altInput: true,
    altFormat: "F j, Y"
  });
</script>

Install with npm

npm install flatpickr-ce
import flatpickr from "flatpickr-ce";
import "flatpickr-ce/dist/flatpickr.css";
flatpickr("#event-date", {
  enableTime: true,
  dateFormat: "Y-m-d H:i"
});

Migrate from flatpickr

Keep existing flatpickr import paths with an npm alias:

npm install flatpickr@npm:flatpickr-ce

Select an appointment time

<input id="appointment" type="text" placeholder="Appointment date and time">
<script>
flatpickr("#appointment", {
  enableTime: true,
  time_24hr: true,
  dateFormat: "Y-m-d H:i",
  minDate: "today",
  disable: [date => date.getDay() === 0 || date.getDay() === 6],
  onChange(selectedDates, dateStr) {
    console.log(dateStr);
  }
});
</script>

Create a time-only input

<input id="office-hours" type="text" placeholder="Select time">
<script>
  flatpickr("#office-hours", {
    enableTime: true,
    noCalendar: true,
    dateFormat: "H:i",
    time_24hr: true,
    minuteIncrement: 15
  });
</script>

Use two inputs for a date range

Load rangePlugin.js after the core script.

<input id="start-date" type="text" placeholder="Start date">
<input id="end-date" type="text" placeholder="End date">
<script src="https://cdn.jsdelivr.net/npm/flatpickr-ce/dist/plugins/rangePlugin.js"></script>
<script>
  flatpickr("#start-date", {
    dateFormat: "Y-m-d",
    plugins: [new rangePlugin({ input: "#end-date" })]
  });
</script>

Add a year-only picker

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr-ce/dist/plugins/yearSelect/style.css">
<input id="graduation-year" type="text" placeholder="Select year">
<script src="https://cdn.jsdelivr.net/npm/flatpickr-ce/dist/plugins/yearSelect/index.js"></script>
<script>
  flatpickr("#graduation-year", {
    plugins: [new yearSelectPlugin({
      yearsPerPage: 12,
      columns: 3
    })]
  });
</script>

All Configuration Options

Date selection and display

OptionDefault and purpose
allowInputfalse. Permit manual typing into the date field.
allowInvalidPreloadfalse. Retain a preloaded value even when it is invalid.
altFormat"F j, Y". Display format for the alternate input.
altInputfalse. Create an alternate, human-readable input while retaining the original field value.
altInputClass"form-control input". CSS classes for the alternate input; original input classes are also inherited.
animateEnabled by default in most browsers. Controls calendar transitions.
appendToUnset. Append the calendar to a supplied HTMLElement (default: document body).
ariaDateFormat"F j, Y". Format of date labels exposed to assistive technology.
autoFillDefaultTimetrue. Populate time controls with the default time when appropriate.
clickOpenstrue. Open the calendar on input interaction.
closeOnSelecttrue. Close the calendar after a completed selection.
conjunction", ". Join dates in multiple-selection mode.
dateFormat"Y-m-d". Format of the stored input value.
defaultDateUnset. Initial selection as a Date, string, timestamp, or array.
disable[]. Exclude dates, date ranges, or dates matching callback functions.
disableMobilefalse. Force the custom picker on mobile when set to true.
enableUnset. Restrict selection to the supplied dates, ranges, or callback matches.
inlinefalse. Render the calendar in the page.
locale"default". Locale identifier or locale configuration object.
maxDateUnset. Latest selectable date, inclusive.
minDateUnset. Earliest selectable date, inclusive.
mode"single". Accepts "single", "multiple", "range", or "time".
monthSelectorType"dropdown". Accepts "dropdown" or "static".
nowCurrent date. Reference date for the calendar when no selection determines the view.
shorthandCurrentMonthfalse. Display abbreviated current-month names.
showMonths1. Number of months visible at once.
weekNumbersfalse. Show week numbers alongside calendar rows.

Time selection

OptionDefault and purpose
defaultHour12. Initial hour when no date is selected.
defaultMinute0. Initial minute when no date is selected.
defaultSeconds0. Initial seconds value.
enableTimefalse. Display time controls.
enableSecondsfalse. Show a seconds input.
hourIncrement1. Step size of the hour control.
maxTimeUnset. Latest selectable time, subject to date constraints.
minTimeUnset. Earliest selectable time, subject to date constraints.
minuteIncrement5. Step size of the minute control.
noCalendarfalse. Hide day selection, usually for a time-only picker.
secondIncrementDefaults to minuteIncrement. Step size of the seconds control.
time_24hrfalse. Use 24-hour time controls.

Layout and extension points

OptionDefault and purpose
ignoredFocusElements[]. Elements whose focus should not dismiss the calendar.
nextArrowBuilt-in SVG. HTML content for the next-month arrow.
position"auto". Vertical/horizontal placement string or positioning callback.
positionElementUnset. Element used as the calendar positioning anchor.
prevArrowBuilt-in SVG. HTML content for the previous-month arrow.
staticfalse. Place calendar in a wrapper beside its input.
wrapfalse. Initialize on a wrapper containing data-input and optional control buttons.

Formatting and callbacks

OptionDefault and purpose
errorHandlerDefault logs warnings to the console. Custom callback receives an Error.
formatDateUnset. Custom formatDate(date, format, locale) callback.
getWeekBuilt-in week-number calculation. A custom getWeek(date) must return a number or trusted text because its result enters calendar HTML.
parseDateUnset. Custom parseDate(dateString, format) callback returning a Date.
plugins[]. Initialize optional plugins.

Wrapped Input Attributes

<div id="date-controls">
  <input type="text" data-input>
  <button type="button" data-toggle>Toggle calendar</button>
  <button type="button" data-clear>Clear date</button>
</div>
<script>
  flatpickr("#date-controls", { wrap: true });
</script>
AttributePurpose
data-inputMarks the date input inside the wrapper.
data-openOpens the calendar when clicked.
data-closeCloses the calendar when clicked.
data-toggleToggles the calendar when clicked.
data-clearClears the selected date when clicked.

Date Formatting Tokens

Use these tokens in dateFormat, altFormat, and ariaDateFormat. Escape literal token characters with a backslash.

TokenMeaning
d / j / JDay with leading zero / without leading zero / with ordinal suffix.
D / l / wShort weekday name / full weekday name / weekday number (0 is Sunday).
WWeek number.
F / MFull / abbreviated month name.
m / nMonth number with / without leading zero.
y / YTwo-digit / four-digit year.
U / ZUnix timestamp in seconds / ISO datetime.
H / G / h24-hour hour / zero-padded 12-hour hour / 12-hour hour.
i / S / sMinutes with leading zero / seconds with leading zero / seconds without leading zero.
KLocale-aware AM/PM marker.

Instance Methods and Properties

MethodPurpose
changeMonth(monthNum, isOffset = true)Move by a month offset; set isOffset to false to use a zero-indexed month.
clear()Remove selected dates and clear the input.
close()Close the popup calendar.
destroy()Remove the picker, clean up listeners, and restore its input.
formatDate(dateObj, formatStr)Format a Date using flatpickr tokens.
jumpToDate(date?, triggerChange?)Move the current calendar view to a date; optionally fire month/year-change hooks.
open()Open the picker.
parseDate(dateStr, dateFormat)Parse a date string; returns a Date or undefined for an invalid value.
redraw()Rebuild the displayed calendar.
set(option, value)Update a configuration option, or pass an object of options.
setDate(date, triggerChange?, dateStrFormat?)Set one or more dates; optionally fire change hooks and specify the supplied string format.
toggle()Toggle the popup calendar.
const picker = flatpickr("#event-date");
picker.setDate("2026-12-10", true);
picker.set("minDate", "2026-12-01");
console.log(picker.selectedDates);
picker.clear();

Instance Properties and Elements

Property or elementPurpose
selectedDatesArray of selected Date objects.
currentYear / currentMonthYear and zero-based month displayed by the calendar.
configResolved configuration, including registered hooks.
inputUnderlying input element.
calendarContainerRoot calendar element.
prevMonthNav / nextMonthNavElements for month navigation.
currentMonthElement / currentYearElementMonth label and year control elements.
daysContainer holding date cells.

Static Utilities

MethodPurpose
flatpickr.parseDate(date, format)Parse a date string using flatpickr tokens.
flatpickr.formatDate(date, format)Format a Date using flatpickr tokens.
flatpickr.localize(locale)Set the default locale for subsequent pickers.
flatpickr.setDefaults(options)Set default options for subsequent pickers.
flatpickr.compareDates(a, b, timeless = true)Return the millisecond difference between two dates; ignore times by default.

Events and Hooks

Each hook accepts a function or an array of functions. Callbacks receive selectedDates, dateStr, and the instance.

HookWhen it runs
onChangeSelected date or time actually changes.
onCloseCalendar closes.
onDayCreateA day cell is constructed; the fourth argument is the cell element.
onDaysBuiltDay cells have been rebuilt after calendar redraw or navigation.
onDestroyInstance is being destroyed.
onKeyDownCalendar receives relevant keyboard input; fourth argument contains the event.
onMonthChangeDisplayed month changes.
onOpenCalendar opens.
onParseConfigConfiguration is parsed during initialization.
onPreCalendarPositionCalendar is about to be positioned.
onReadyInstance finishes initialization.
onValueUpdateInput value is updated.
onYearChangeDisplayed year changes.

Optional Plugins and Their Options

For browser use, load each plugin script after the core flatpickr-ce script. Pass plugin settings inside the plugins array.

Plugin scriptPurpose and options
rangePlugin.jsrangePlugin({ input, position }): Two-input range selection; input is a selector/element for the end input, and position accepts "left".
weekSelect/weekSelect.jsweekSelect(): Pick a week. No configuration parameters.
monthSelect/index.jsmonthSelectPlugin({ shorthand, dateFormat, altFormat, theme }): Month-only selection. Defaults: false, "F Y", "F Y", "light". Load monthSelect/style.css.
yearSelect/index.jsyearSelectPlugin({ yearsPerPage, columns, dateFormat, altFormat, theme }): Year-only selection. Defaults: 12, 3, "Y", "Y", "light". Load yearSelect/style.css.
confirmDate/confirmDate.jsconfirmDatePlugin({ confirmIcon, confirmText, showAlways, theme }): Add a confirmation control. Defaults include "OK ", false, "light". Load confirmDate/confirmDate.css.
minMaxTimePlugin.jsminMaxTimePlugin({ table, getTimeLimits, tableDateFormat }): Date-specific time limits from a lookup object or callback; default format "Y-m-d".
scrollPlugin.jsscrollPlugin(): Enable wheel interactions on calendar controls. No configuration parameters.
labelPlugin/labelPlugin.jslabelPlugin(): Keep an input label connected to the visible alternate or mobile input. No configuration parameters.
momentPlugin.jsmomentPlugin({ moment }): Integrate Moment.js into time stepping. Load Moment.js before the plugin; the core picker has no Moment.js dependency.

Alternatives and Related Resources

You Might Be Interested In:


Leave a Reply