Skip to main content

Months Navigation

Default Month

By default, DayPicker renders the current month. You can change the default month by setting the defaultMonth prop to a specific date.

For example, to render a calendar starting from September 1979:

<DayPicker defaultMonth={new Date(1979, 8)} />

Controlling the Month

To programmatically control the month displayed when navigating, use the month and onMonthChange props.

import { useState } from "react";

import { DayPicker } from "react-day-picker";

export function Controlled() {
const [month, setMonth] = useState(new Date(2024, 9)); // Start from October 2024
return <DayPicker month={month} onMonthChange={setMonth} />;
}

Today Button

To implement a Go to Today button, set month to the current date when the button is clicked.

import { useState } from "react";

import { addMonths } from "date-fns";
import { DayPicker } from "react-day-picker";

export function Controlled() {
const today = new Date();
const nextMonth = addMonths(today, 1);

const [month, setMonth] = useState(nextMonth);

return (
<>
<DayPicker month={month} onMonthChange={setMonth} />
<button onClick={() => setMonth(today)}>Go to Today</button>
</>
);
}

Start and End Dates

Limit the dates the user can navigate to by using the startMonth and endMonth props.

<DayPicker startMonth={new Date(2024, 0)} endMonth={new Date(2025, 11)} />

Animating Month Transitions

To animate the transition between months, set the animate prop to true:

<DayPicker animate />

Customizing the Animation

Use the supported CSS variables to customize the animation duration or timing function:

.custom-animate {
--rdp-animation_duration: 0.1s; /* Change the duration of the transition. */
--rdp-animation_timing: ease-in; /* Choose a different timing function. */
}
<DayPicker animate className="custom-animate" />

Accessibility Note

To improve accessibility for users who prefer reduced motion, you can use the prefers-reduced-motion media query to disable animations.

@media (prefers-reduced-motion: reduce) {
.custom-animate {
--rdp-animation_duration: 0s;
}
}

Changing the Animation Functions

For advanced customization, you can override the default style with your own animation functions:

.rdp-caption_after_enter {
animation:; /* Your value here */
}
Class Names Used For Animations
Advanced Feature

Customizing the animation function, such as for an up/down transition, can be challenging due to the HTML table structure of the grid. We may improve this in a future version. Please leave your feedback in DayPicker Discussions.