createStyles
All Mantine components are built with emotion based css-in-js library.
We recommend using createStyles to create styles for the rest of your application
as it provides the most convenient way to utilize Mantine theme, but it is not required
– you can use any other styling tools and languages.
Features
- As fast and lightweight as emotion:
createStylesextends @emotion/react - Subscribes to your Mantine theming context
- Supports all emotion features: automatic critical css extraction during server side rendering, lazy evaluation, dynamic theming, etc.
- Server side rendering support: Next.js, Gatsby or any other environment
- Fully featured TypeScript support
Basic usage
Pseudo-classes
You can add pseudo-classes the same way as in any css-preprocessor like Sass:
Styles parameters
You can receive any amount of parameters as second argument of createStyles function,
latter you will need to pass those parameters as argument to useStyles hook:
Composition and nested selectors
Since createStyles produces scoped class names you will need to create a reference to selector
in order to get static selector. createStyles receives getRef function to handle static selector creation:
Classes merging (cx function)
To merge class names use cx function, it has the same api as clsx package.
!important: Do not use external libraries like classnames
or clsx with class names created with createStyles function
as it will produce styles collisions.
Media queries
You can use nested media queries like in Sass. Within query body you can use theme.breakpoints
defined via MantineProvider or just static values:
Keyframes
Inline styles
Most of Mantine components support Styles API.
You can override default component styles inline or using MantineProvider
the same way as with createStyles:
Using createStyles without @mantine/core
You can use createStyles and MantineProvider without any other Mantine packages:
After installation you can import createStyles and other function from @mantine/styles instead of @mantine/core and use it separately:
Can I use other css-in-js libraries or SCSS with Mantine?
Yes, you can. But please note that Mantine already uses emotion and you may
have styles collisions and would have to overwrite styles with !important. Please consider
choosing createStyle before picking other libraries.