Skip to main content

Styling DayPicker

DayPicker comes with for a minimal, lightweight appearance: import react-day-picker/dist/style.css into your root component, or bundle it within your build pipeline.

// Your App.tsx file
import 'react-day-picker/dist/style.css';

This will add the DayPicker stylesheet into your app. The stylesheet includes some CSS global variables, to override colors and sizes:

.rdp {
--rdp-cell-size: 40px; /* Size of the day cells. */
--rdp-caption-font-size: 18px; /* Font size for the caption labels. */
--rdp-accent-color: #0000ff; /* Accent color for the background of selected days. */
--rdp-background-color: #e7edff; /* Background color for the hovered/focused elements. */
--rdp-accent-color-dark: #3003e1; /* Accent color for the background of selected days (to use in dark-mode). */
--rdp-background-color-dark: #180270; /* Background color for the hovered/focused elements (to use in dark-mode). */
--rdp-outline: 2px solid var(--rdp-accent-color); /* Outline border for focused elements */
--rdp-outline-selected: 3px solid var(--rdp-accent-color); /* Outline border for focused _and_ selected elements */
--rdp-selected-color: #fff; /* Color of selected day text */
}

Styling Modifiers

Use the modifiersClassNames or modifiersStyles props to change the class name, or the inline-style, of the days with active modifiers.

You can style an internal modifier, like selected, hidden, today..., or your own custom modifiers.

|
import React, { useState } from 'react';

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

const css = `
.my-selected:not([disabled]) {
font-weight: bold;
border: 2px solid currentColor;
}
.my-selected:hover:not([disabled]) {
border-color: blue;
color: blue;
}
.my-today {
font-weight: bold;
font-size: 140%;
color: red;
}
`;

export default function App() {
const [selectedDay, setSelectedDay] = useState<Date[]>();
return (
<>
<style>{css}</style>
<DayPicker
mode="multiple"
selected={selectedDay}
max={3}
onSelect={setSelectedDay}
modifiersClassNames={{
selected: 'my-selected',
today: 'my-today'
}}
modifiersStyles={{
disabled: { fontSize: '75%' }
}}
footer="Try to select 3+ days to see the custom class names or styles applied."
/>
</>
);
}
SuMoTuWeThFrSa
Try to select 3+ days to see the custom class names or styles applied.

With CSS modules, pass the generated class name instead:

import style from './day-picker.module.css';

function App() {
return (
<DayPicker
mode="multiple"
modifiersClassNames={{
selected: style.selected,
today: style.today
}}
/>
);
}

Styling DayPicker elements

You can override the appearance of the HTML elements composing DayPicker, such as heading, cells, buttons. The elements that can be styled are listed in the StyledElement type.

Pure CSS solution

This approach involves just CSS and works well if you need the same style across your app.

  1. create a new CSS file to import after the default style, e.g. day-picker.css

    // Your App.tsx file
    import 'react-day-picker/dist/style.css';
    import './day-picker.css';
  2. change the appearance of DayPicker overriding the original selectors in the new CSS file. Refer to the stylesheet source to find the right selectors to override.

    /* day-picker.css */
    /* Paint the today's date in red */
    .rdp-day_today:not(.rdp-day_outside) {
    color: red;
    }
note

Keep in mind that the selectors may be a bit complex, and they may break in future style updates.

Using CSS Modules

With CSS modules, import instead react-day-picker/dist/style.module.css (not style.css) and pass the generated class names to the classNames prop.

|
import React from 'react';

import { ClassNames, DayPicker } from 'react-day-picker';
import styles from 'react-day-picker/dist/style.module.css';

export default function App() {
const [selectedDay, setSelectedDay] = React.useState<Date>();

const classNames: ClassNames = {
...styles,
head: 'custom-head'
};
return (
<>
<style>{`.custom-head { color: red }`}</style>
<DayPicker
mode="single"
classNames={classNames}
selected={selectedDay}
onSelect={setSelectedDay}
/>
</>
);
}
SuMoTuWeThFrSa

Using Inline Styles

To change the appearance of any DayPicker element via inline-styles use the styles prop.

|
import React from 'react';

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

export default function App() {
return (
<DayPicker
styles={{
caption: { color: 'red' }
}}
/>
);
}
SuMoTuWeThFrSa