Home / Forms and Input / Date Range Picker

Date Range Picker in JavaScript, Free with Live Demo

Free date range picker in plain JavaScript. Two month calendar, blocked dates, minimum nights, hover preview, quick presets and keyboard navigation. No library.

Open live demoDownload HTML fileView code on GitHub
Date Range Picker JavaScript project: a two month calendar for picking check in and check out dates

Runs on: Date and Intl.DateTimeFormat. Works in all modern browsers.

What is the Date Range Picker?

A booking style calendar showing two months side by side. Click a check in date and a check out date, and the range and number of nights appear.

Taken and past dates are crossed out, a range cannot include a taken night, and there is a two night minimum. Presets pick a weekend or a week in one click.

Good for

  • Hotel and holiday rental booking
  • Car and equipment hire
  • Leave and holiday requests
  • Report and analytics date filters

What this project does

How it works

  1. Build the grid from datesFor each month the script works out which weekday the 1st falls on, adds empty cells, then one button per day.
  2. Two clicks make a rangeThe first click sets check in. The second sets check out if it is later, long enough and has no taken nights in between.
  3. Keyboard as a gridOnly one day is in the Tab order. Arrow keys move a day or a week, and the calendar moves to the next month when needed.

The key JavaScript

This is the heart of the project. The full file has the rest, including the screen layout and error handling.

function monthGrid(year, month) {
  const firstWeekday = (new Date(year, month, 1).getDay() + 6) % 7; // Monday first
  const days = new Date(year, month + 1, 0).getDate();              // days in month
  const cells = Array(firstWeekday).fill(null);
  for (let d = 1; d <= days; d++) cells.push(new Date(year, month, d));
  return cells;
}
const nights = Math.round((checkOut - checkIn) / 86400000);

How to use it

  1. Click Download HTML file above.
  2. Open the file in a code editor, like VS Code.
  3. Run it from a local server with npx serve . so the camera, microphone and AI features are allowed.
  4. Change the text and colors, then upload it to GitHub Pages, Netlify or your own site. It is one file with no build step.

Questions people ask

Why not use input type date?

The native picker selects one date and cannot show taken dates or a range, which booking sites need.

How do I load real taken dates?

Fetch them from your booking system and add each date to the blocked set before drawing.

Does it handle time zones?

Dates are treated as local calendar days, which is what guests expect for check in and check out.

More Forms and Input projects