Theme object
Mantine theme is an object where your application's colors, fonts, spacing, border-radius and other design tokens are stored.
Usage
To customize theme, pass theme override object to MantineProvider theme
prop.
Theme override will be deeply merged with the default theme.
Theme properties
autoContrast
autoContrast
controls whether text color should be changed based on the given color
prop
in the following components:
- ActionIcon with
variant="filled"
only - Alert with
variant="filled"
only - Avatar with
variant="filled"
only - Badge with
variant="filled"
only - Button with
variant="filled"
only - Chip with
variant="filled"
only - NavLink with
variant="filled"
only - ThemeIcon with
variant="filled"
only - Checkbox with
variant="filled"
only - Radio with
variant="filled"
only - Tabs with
variant="pills"
only - SegmentedControl
- Stepper
- Pagination
- Progress
- Indicator
- Timeline
- Spotlight
- All @mantine/dates components that are based on Calendar component
autoContrast
checks whether the given color luminosity is above or below the luminanceThreshold
value
and changes text color to either theme.white
or theme.black
accordingly.
autoContrast
can be set globally on the theme level or individually for each component via autoContrast
prop,
except for Spotlight and @mantine/dates components which only support global theme setting.
autoContrast: true
autoContrast: false
luminanceThreshold
luminanceThreshold
controls which luminance value is used to determine if text color should be light or dark.
It is used only if theme.autoContrast
is set to true
. Default value is 0.3
.
focusRing
theme.focusRing
controls focus ring styles, it supports the following values:
auto
(default and recommended) – focus ring is visible only when the user navigates with keyboard, this is the default browser behavior for native interactive elementsalways
– focus ring is visible when user navigates with keyboard and mouse, for example, the focus ring will be visible when user clicks on a buttonnever
– focus ring is always hidden, it is not recommended – users who navigate with keyboard will not have visual indication of the current focused element
Focus ring: auto
Focus ring: always
Focus ring: never
focusClassName
theme.focusClassName
is a CSS class that is added to elements that have focus styles, for example, Button or ActionIcon.
It can be used to customize focus ring styles of all interactive components except inputs. Note that when theme.focusClassName
is set, theme.focusRing
is ignored.
:focus-visible selector
:focus-visible
selector is supported by more than 91% of browsers (data from April 2023). Safari browsers added support for it in version 15.4 (released in March 2022). If you need to support Safari 15.3 and older, you can use focus-visible polyfill or provide a fallback with:focus
pseudo-class.
activeClassName
theme.activeClassName
is a CSS class that is added to elements that have active styles, for example, Button or ActionIcon.
It can be used to customize active styles of all interactive components.
To disable active styles for all components, set theme.activeClassName
to an empty string:
defaultRadius
theme.defaultRadius
controls the default border-radius
property in most components, for example, Button or TextInput.
You can set to either one of the values from theme.radius
or a number/string to use exact value. Note that numbers are treated as pixels, but
converted to rem. For example, theme.defaultRadius: 4
will be converted to 0.25rem
.
You can learn more about rem conversion in the rem units guide.
cursorType
theme.cursorType
controls the default cursor type for interactive elements,
that do not have cursor: pointer
styles by default. For example, Checkbox and NativeSelect.
defaultGradient
theme.defaultGradient
controls the default gradient configuration for components that support variant="gradient"
(Button, ActionIcon, Badge, etc.).
components
theme.components
allows to override components default props and styles with classNames
and styles
properties.
You can learn more about these features in default props and Styles API guides.
other
theme.other
is an object that can be used to store any other properties that you want to access with the theme objects.
Store theme override object in a variable
To store theme override object in a variable, use createTheme
function:
Merge multiple theme overrides
Use mergeThemeOverrides
function to merge multiple themes into one theme override object:
use-mantine-theme hook
useMantineTheme
hook returns theme object from MantineProvider context:
Default theme
You can import default theme object from @mantine/core
package. It includes
all theme properties with default values. When you pass theme override to
MantineProvider, it will be deeply merged with
the default theme. You can find contents of DEFAULT_THEME
object
on this page.
Access theme outside of components
To access theme outside of components, you need to create a full theme object (your theme override merged with the default theme).
Then you will be able to import it anywhere in your application: