Usage with Next.js

Mantine is fully compatible with Next.js, follow following guide to setup your application

Get started with template

If you are starting new project you can skip all configuration steps and use Next.js template. To get started follow this link and create new repository. Alternatively you can download or clone repository to get started on your machine.

Adding to existing Next.js project

  1. Create pages/_document.tsx file:
import Document, { Html, Head, Main, NextScript, DocumentContext } from 'next/document';
import { SsrProvider, SheetsRegistry, ServerStyles } from '@mantine/core';
export default class _Document extends Document {
static async getInitialProps(ctx: DocumentContext) {
const registry = new SheetsRegistry();
const originalRenderPage = ctx.renderPage;
ctx.renderPage = () =>
// eslint-disable-next-line react/display-name
enhanceApp: (App) => (props) =>
<SsrProvider registry={registry}>
<App {...props} />
const initialProps = await Document.getInitialProps(ctx);
return {
styles: (
<ServerStyles registry={registry} />
render() {
return (
<link rel="icon" href="link to favicon" />
<Main />
<NextScript />
  1. Replace your pages/_app.tsx with
import { AppProps } from 'next/app';
import Head from 'next/head';
import {
} from '@mantine/core';
export default function App(props: AppProps) {
const { Component, pageProps } = props;
return (
<title>Mantine next example</title>
<meta name="viewport" content="minimum-scale=1, initial-scale=1, width=device-width" />
/* Put your mantine theme override here */
colorScheme: 'light',
{/* NormalizeCSS and GlobalStyles are optional */}
<NormalizeCSS />
<GlobalStyles />
<Component {...pageProps} />

All done! You can start developing your application. If you experience any issues with Next.js please report an issue.

NextLink component

Some Mantine components support changing root element via component prop (e.g. Button and ActionIcon). In order to make this prop work correctly with Next Link component create NextLink wrapper in your components folder:

import React, { forwardRef } from 'react';
import Link from 'next/link';
export const NextLink = forwardRef(
{ href, ...others }: React.ComponentPropsWithoutRef<typeof Link>,
ref: React.ForwardedRef<HTMLAnchorElement>
) => (
<Link href={href}>
{/* eslint-disable-next-line jsx-a11y/anchor-has-content */}
<a {...others} ref={ref} />

Then you can use it with any Mantine component:

import { Button, ActionIcon } from '@mantine/core';
import { NextLink } from '../components/NextLink/NextLink';
function Demo() {
return (
<Button component={NextLink} href="/hello">
My next link button
<ActionIcon component={NextLink} href="/hello">
Build fully functional accessible web applications with ease
Your feedback is most valuable contribution to the project, please share how you use Mantine, what features are missing and what is done good
Leave feedback