Usage with Next.js

Get started with template

The easiest way to get started is to use default or minimal template on GitHub:

  1. Open default template or minimal template
  2. Click Use this template button
  3. Clone or download the repository
  4. Install dependencies: yarn
  5. Start development server: npm run dev

Generate new application

Init new application:

yarn create next-app --typescript
Choose packages that you will use in your application:
Hooks for state and UI management
Core components library: inputs, buttons, overlays, etc.
Form management library
Date inputs, calendars
Notifications system
Code highlight with your theme colors and styles
Rich text editor based on Quill.js
Capture files with drag and drop
Embla based carousel component
Overlay command center
Centralized modals manager
Navigation progress
Install dependencies:
yarn add @mantine/core @mantine/hooks @mantine/next @emotion/server @emotion/react
npm install @mantine/core @mantine/hooks @mantine/next @emotion/server @emotion/react

Create pages/_document.tsx file:

import { createGetInitialProps } from '@mantine/next';
import Document, { Head, Html, Main, NextScript } from 'next/document';
const getInitialProps = createGetInitialProps();
export default class _Document extends Document {
static getInitialProps = getInitialProps;
render() {
return (
<Head />
<Main />
<NextScript />

Add MantineProvider to pages/_app.tsx:

import { AppProps } from 'next/app';
import Head from 'next/head';
import { MantineProvider } from '@mantine/core';
export default function App(props: AppProps) {
const { Component, pageProps } = props;
return (
<title>Page title</title>
<meta name="viewport" content="minimum-scale=1, initial-scale=1, width=device-width" />
/** Put your mantine theme override here */
colorScheme: 'light',
<Component {...pageProps} />

All set! Start development server:

npm run dev

Create your own getInitialProps

In some cases you will need to have access to getInitialProps in Next Document, for that you will need to setup Mantine ssr styles extraction on your side:

import Document, { DocumentContext } from 'next/document';
import { ServerStyles, createStylesServer } from '@mantine/next';
// optional: you can provide your cache as a fist argument in createStylesServer function
const stylesServer = createStylesServer();
export default class _Document extends Document {
static async getInitialProps(ctx: DocumentContext) {
const initialProps = await Document.getInitialProps(ctx);
// Add your app specific logic here
return {
styles: [
<ServerStyles html={initialProps.html} server={stylesServer} key="styles" />,

Mantine components with Next Link

You can use polymorphic components (Button, ActionIcon, Anchor, etc.) with Next Link, to do so:

  • set component prop to a
  • wrap it with Link
import Link from 'next/link';
import { Button } from '@mantine/core';
function Demo() {
return (
<Link href="/hello" passHref>
<Button component="a">Next link button</Button>

NextLink component

@mantine/next package exports NextLink component that can be used when it is not possible to use Link component, for example, with Tooltip component:

import { NextLink } from '@mantine/next';
import { Button } from '@mantine/core';
function Demo() {
return (
<Button component={NextLink} href="/hello">
Next link button

Server side rendering with custom emotion cache

Follow custom emotion cache guide to setup server side rendering with emotion cache. If you do not follow this guide, server side rendering will not work.

Next steps