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:
:root {
--rdp-cell-size: 40px;
--rdp-accent-color: #0000ff;
--rdp-background-color: #e7edff;
/* Switch to dark colors for dark themes */
--rdp-accent-color-dark: #3003e1;
--rdp-background-color-dark: #180270;
/* Outline border for focused elements */
--rdp-outline: 2px solid var(--rdp-accent-color);
/* Outline border for focused and selected elements */
--rdp-outline-selected: 2px solid rgba(0, 0, 0, 0.75);
}
Styling Modifiers​
To customize the style of days with active modifiers, such as selected
, hidden
, today
... use modifiersClassNames prop to assign those days a custom class name. You can also use modifiersStyles to set the inline style.
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." /> </> ); }
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.
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';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} /> </> ); }
Using Inline Styles​
To change the appearance of any DayPicker element via inline-styles use the
styles
prop.