MantineProvider
MantineProvider component can be used to change theme globally. It is not required if you decide to use default theme:
Theme object
Mantine theme is an object where your application's colors, fonts, spacing, border-radius and other design tokens are stored.
Pass theme object to MantineProvider to change global styles:
Store theme override object in a variable
To store theme override object in a variable use MantineThemeOverride
type:
use-mantine-theme hook
Hook returns theme from MantineProvider context or default theme if you did not wrap application with MantineProvider.
Nested MantineProviders
If some parts of your application require different theme settings, you can wrap them with another MantineProvider:
Nested MantineProviders will inherit theme
override, emotionOptions
, defaultProps
and styles
from
parent provider if inherit
prop is set:
Styles on MantineProvider
You can add context styles to components that support Styles API with MantineProvider. All components that are rendered inside MantineProvider will inherit those styles:
If component does not specify Styles API selectors, then in most cases you can add styles using root
selector:
Classes on MantineProvider
Same as with styles
you can add classes to all components with classNames
prop on MantineProvider:
This approach is useful when you want to styles components with utility based CSS libraries.
Mantine CSS variables
If you prefer to style components with CSS/SCSS or other styling solutions that do not have access to Mantine theme
context, then you can use Mantine CSS variables. To add css variables set withCSSVariables
prop on MantineProvider:
Then you will be able to use variables anywhere in your CSS:
Mantine exposes the following CSS variables based on theme
you provide:
--mantine-color-white
--mantine-color-black
--mantine-transition-timing-function
--mantine-line-height
--mantine-font-family
--mantine-font-family-monospace
--mantine-font-family-headings
--mantine-heading-font-weight
--mantine-shadow-{size}
, e.g.--mantine-shadow-sm
,--mantine-shadow-xl
--mantine-radius-{size}
, e.g.--mantine-radius-sm
,--mantine-radius-xl
--mantine-spacing-{size}
, e.g.--mantine-spacing-sm
,--mantine-spacing-xl
--mantine-font-size-{size}
, e.g.--mantine-font-size-sm
,--mantine-font-size-xl
--mantine-color-{color}-{shade}
, e.g.--mantine-color-blue-6
,--mantine-color-gray-0
--mantine-{heading}-font-size
, e.g.--mantine-h1-font-size
--mantine-{heading}-line-height
, e.g,--mantine-h3-line-height
Default props on MantineProvider
All Mantine components support default props on MantineProvider:
Normalize.css and global styles
MantineProvider includes normalize.css and some extra global styles added to body element:
- background-color to
theme.colors.dark[7]
in dark color scheme andtheme.white
in light - color to
theme.colors.dark[0]
in dark color scheme andtheme.black
in light - font-family and font-smoothing based on theme
- font-size to
theme.fontSize.md
To enable these global styles, set withNormalizeCSS
and withGlobalStyles
props:
Configure emotion
You can provide emotion options to MantineProvider to configure emotion cache:
key
(required) – the prefix before class names, defaults tomantine
container
– a DOM node that emotion will insert all of its style tags into. This is useful for inserting styles into iframes.prepend
- a boolean representing whether to prepend rather than append style tags into the specified container DOM nodestylisPlugins
– an array of Stylis plugins that will be run by Stylis during preprocessing, for example stylis-plugin-rtl can be used to add RTL support
Change styles insertion point
By default, Mantine components styles are prepended to head to allow overrides.
To make Mantine styles override other styles, set prepend
to false
.
With this option styles will be added at the end of head
element:
Change classes prefix
To change classes prefix set emotionOptions.key
property:
Now classes will follow this pattern: custom-key-{random part}
.