MantineProvider
MantineProvider component can be used to change theme. It is not required if you decide to use the default theme.
Usage
CSS reset and global styles
MantineProvider
has an option to add css reset similar to normalize.css (withNormalizeCSS
)
and global styles (withGlobalStyles
). It is recommended to enable these options.
withGlobalStyles
prop will add the following styles:
- 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.fontSizes.md
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 to the :root
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
Nested MantineProviders
If some parts of your application require different theme settings, you can wrap them with another MantineProvider
:
Note that nested MantineProvider
will inherit theme
override from parent provider only 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:
Root selector
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
.
This approach is useful when you want to styles components with utility based CSS libraries.
Variants on MantineProvider
To create new variants set variants
property for any Mantine component.
variants
property must be an object of functions:
- object key is variant name
- function accepts three arguments: theme, params and context (object with
variant
andsize
keys) - function must return an object with component styles, you can use any selectors specified in component Styles API
For example you can create new variants for Button:
Sizes on MantineProvider
To create new sizes set sizes
property for Mantine components that support size
prop.
sizes
property must be an object of functions:
- object key is size name
- function accepts three arguments: theme, params and context (object with
variant
andsize
keys) - function must return an object with component styles, you can use any selectors specified in component Styles API
For example you can create new sizes for Button: