API overview
This guide will help you get familiar with core Mantine concepts. Please read this guide, theming and styles sections before starting development to learn about all of the available theming and styling features.
MantineProvider
MantineProvider is required to be rendered at the root of your application. It is responsible for:
- Providing theme context
- Adding CSS variables to the document
- Managing color scheme (light, dark, auto)
Theme object
Theme object stores design tokens, components default props, context styles
and other data that can be accessed by any Mantine component. Most of the theme
values are exposed as
CSS variables and can be accessed both in JavaScript and CSS.
Access theme values in styles:
Access theme values in JavaScript:
Colors
Colors are stored in theme.colors
object and are exposed as CSS variables.
Each color must have at least 10 shades. You can generate new colors based on a single color value
with the colors generator.
Colors are numbered from 0 to 9 where 0 is the lightest and 9 is the darkest color. Example of blue
color from the default theme:
blue 0
#e7f5ff
blue 1
#d0ebff
blue 2
#a5d8ff
blue 3
#74c0fc
blue 4
#4dabf7
blue 5
#339af0
blue 6
#228be6
blue 7
#1c7ed6
blue 8
#1971c2
blue 9
#1864ab
To access colors in styles use CSS variables:
CSS modules
All Mantine components use CSS modules for styling. It is recommended to use CSS modules in your project as well, but it is not required – Mantine components are fully compatible with any third-party styling solution and native CSS.
CSS modules are available in most modern frameworks out of the box. To use them, create a file with .module.css
extension:
And then import it in your component:
PostCSS preset
postcss-preset-mantine provides several CSS functions and mixins to simplify your styles. It is not required to use it, but highly recommended. All demos that feature styles assume that you have this preset installed.
postcss-preset-mantine allows you to use functions and mixins in .css
files:
Vanilla extract
Vanilla extract is a good alternative to CSS modules if you
prefer to write styles in JavaScript. Mantine provides Vanilla extract integration
with @mantine/vanilla-extract
package.
CSS variables
Theme values are converted to CSS variables and are available to
use in your styles. All Mantine CSS variables are prefixed with --mantine-
, for example:
theme.fontFamily
→--mantine-font-family
theme.colors.blue[9]
→--mantine-color-blue-9
theme.spacing.xl
→--mantine-spacing-xl
Most of Mantine components have associated CSS variables that can be
customized in theme or inline with vars
prop. Example of customizing
Button CSS variables to add new xxl
and xxs
sizes:
Styles API
Styles API is a set of props and techniques that allows you to customize styles of any element inside Mantine component inline or with theme object. All Mantine components that have styles support Styles API.
Every Mantine component has a set of elements names that can be used to apply styles to inner elements inside the component. Example of TextInput component selectors:
These selectors can be used to apply styles to inner elements with classNames or styles props:
Color scheme
All Mantine components support light
, dark
and auto
color schemes. By default,
the color scheme is light
, it can be changed by the user and will be persisted in localStorage
.
You can configure the default color scheme on MantineProvider:
And use useMantineColorScheme hook to create color scheme toggle control:
Unstyled components
You can use Mantine as a headless UI library. To do that, simply do not import @mantine/*/styles.css
in your application. Then you will be able to apply styles to Mantine components using the Styles API
with a styling solution of your choice.
All components also support unstyled prop that removes all library styles from the component: