# Mantine
Mantine is a fully featured React components library with a focus on usability, accessibility, and developer experience.
## Overview and Key Links
- **Documentation**: [https://mantine.dev/](https://mantine.dev/)
- **GitHub Repository**: [https://github.com/mantinedev/mantine](https://github.com/mantinedev/mantine)
- **Mantine UI**: [https://ui.mantine.dev/](https://ui.mantine.dev/)
- **Mantine Help Center**: [https://mantine.dev/help-center/](https://mantine.dev/help-center/)
- **Colors Generator**: [https://mantine.dev/colors-generator/](https://mantine.dev/colors-generator/)
- **NPM**: [https://www.npmjs.com/org/mantine](https://www.npmjs.com/org/mantine)
## Installation & Getting Started
```bash
# Create a new project with Mantine template
# For Vite (SPA)
npm create vite@latest my-app -- --template react-ts
cd my-app
npm install @mantine/core @mantine/hooks @emotion/react
# For Next.js (SSR)
npx create-next-app --typescript my-app
cd my-app
npm install @mantine/core @mantine/hooks @emotion/react
```
Import styles at the root of your application:
```jsx
import '@mantine/core/styles.css';
```
Wrap your application with MantineProvider:
```jsx
import { MantineProvider } from '@mantine/core';
function App() {
return (
);
}
```
## Core Concepts
### Theme System
Mantine uses a theme object to control the appearance of all components. The theme is provided through the MantineProvider component and can be customized.
```jsx
import { MantineProvider, createTheme } from '@mantine/core';
const theme = createTheme({
fontFamily: 'Verdana, sans-serif',
primaryColor: 'blue',
colors: {
// Add custom colors
'ocean-blue': ['#7AD1DD', '#5FCCDB', '#44CADC', '#2AC9DE', '#1AC2D9', '#11B7CD', '#09ADC3', '#0E99AC', '#128797', '#147885'],
},
});
function App() {
return (
);
}
```
### Color System
Mantine provides a rich color system with predefined colors and the ability to add custom colors:
- Colors are defined as arrays of 10 shades (0-9), where 0 is lightest and 9 is darkest
- Default colors: white, black, dark, gray, red, pink, grape, violet, indigo, blue, cyan, teal, green, lime, yellow, orange
- Primary color is customizable via `theme.primaryColor`
- Color is accessed via CSS variables: `--mantine-color-{colorName}-{shade}`
- Primary color shortcuts: `--mantine-primary-color-{shade}`
### CSS Variables
Mantine uses CSS variables for styling:
- `--mantine-color-{name}-{shade}`: Color variables
- `--mantine-primary-color-{shade}`: Primary color variables
- `--mantine-spacing-{size}`: Spacing variables (xs, sm, md, lg, xl)
- `--mantine-font-family`: Font family variable
- `--mantine-font-size-{size}`: Font size variables
### CSS Modules
Mantine components use CSS modules for styling. You can create your own `.module.css` files to customize components:
```css
/* Button.module.css */
.button {
padding: 10px 15px;
background-color: var(--mantine-primary-color-6);
}
```
```jsx
import classes from './Button.module.css';
function Demo() {
return ;
}
```
### Color Schemes
Mantine supports light and dark color schemes out of the box:
```jsx
import { MantineProvider } from '@mantine/core';
function App() {
return (
);
}
```
## Core Components
### Layout Components
#### AppShell
A responsive shell for your application with configurable header, navbar and footer.
```jsx
import { AppShell, Burger } from '@mantine/core';
import { useState } from 'react';
function Demo() {
const [opened, setOpened] = useState(false);
return (
setOpened(!opened)} />
Navbar contentMain content
);
}
```
[Documentation](https://mantine.dev/core/app-shell) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/core/src/components/AppShell)
#### Container
Center content horizontally with predefined max-width.
```jsx
import { Container } from '@mantine/core';
function Demo() {
return (
Centered content with sm size
);
}
```
[Documentation](https://mantine.dev/core/container) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/core/src/components/Container)
**Available Sizes**:
- `xs`: 576px
- `sm`: 768px
- `md`: 992px
- `lg`: 1200px
- `xl`: 1400px
**Best Practices**:
- Use consistent container sizes throughout your application
- Combine with responsive props for better mobile experiences
- Use the `fluid` prop for full-width containers with padding
#### Flex
Responsive flexbox container.
```jsx
import { Flex } from '@mantine/core';
function Demo() {
return (
1
2
3
);
}
```
[Documentation](https://mantine.dev/core/flex) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/core/src/components/Flex)
#### Grid
Responsive grid system with support for flexbox alignments.
```jsx
import { Grid } from '@mantine/core';
function Demo() {
return (
12
);
}
```
[Documentation](https://mantine.dev/core/grid) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/core/src/components/Grid)
#### Group
Arrange items with equal spacing in a row.
```jsx
import { Group } from '@mantine/core';
function Demo() {
return (
1
2
3
);
}
```
[Documentation](https://mantine.dev/core/group) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/core/src/components/Group)
#### SimpleGrid
Responsive grid where each item takes equal amount of space.
```jsx
import { SimpleGrid } from '@mantine/core';
function Demo() {
return (
);
}
```
[Documentation](https://mantine.dev/core/table) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/core/src/components/Table)
### Typography Components
#### Text
Display text with theme styles.
```jsx
import { Text } from '@mantine/core';
function Demo() {
return (
<>
Extra small textSmall textDefault textLarge textExtra large textBold textItalic textUnderlined textBlue text
>
);
}
```
[Documentation](https://mantine.dev/core/text) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/core/src/components/Text)
#### Title
Display section headings with theme styles.
```jsx
import { Title } from '@mantine/core';
function Demo() {
return (
<>
This is h1 titleThis is h2 titleThis is h3 titleThis is h4 titleThis is h5 titleThis is h6 title
>
);
}
```
[Documentation](https://mantine.dev/core/title) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/core/src/components/Title)
#### List
Display ordered or unordered list.
```jsx
import { List } from '@mantine/core';
function Demo() {
return (
Clone or download repository from GitHubInstall dependencies with yarnTo start development server run npm start commandRun tests to make sure your changes do not break the buildSubmit a pull request once you are done
);
}
```
[Documentation](https://mantine.dev/core/list) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/core/src/components/List)
## Mantine Form
`@mantine/form` provides form state management.
```jsx
import { useForm } from '@mantine/form';
import { TextInput, Button, Box } from '@mantine/core';
function Demo() {
const form = useForm({
initialValues: {
email: '',
name: '',
},
validate: {
email: (value) => (/^\S+@\S+$/.test(value) ? null : 'Invalid email'),
name: (value) => (value.length < 2 ? 'Name must have at least 2 letters' : null),
},
});
return (
);
}
```
[Form Documentation](https://mantine.dev/form/use-form) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/form/src/use-form)
## Mantine Dates
The `@mantine/dates` package provides date and time related components.
### DatesProvider
Provides context to dates components.
```jsx
import { DatesProvider } from '@mantine/dates';
function Demo() {
return (
{/* Your dates components */}
);
}
```
[Documentation](https://mantine.dev/dates/getting-started) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/dates/src/DatesProvider)
### Calendar
Base component for custom date pickers.
```jsx
import { Calendar } from '@mantine/dates';
import { useState } from 'react';
function Demo() {
const [value, setValue] = useState(null);
return (
);
}
```
[Documentation](https://mantine.dev/dates/calendar) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/dates/src/components/Calendar)
### DateInput
Input to capture date from user.
```jsx
import { DateInput } from '@mantine/dates';
import { useState } from 'react';
function Demo() {
const [value, setValue] = useState(null);
return (
);
}
```
[Documentation](https://mantine.dev/dates/date-input) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/dates/src/components/DateInput)
### DateTimePicker
Input to capture date and time from user.
```jsx
import { DateTimePicker } from '@mantine/dates';
import { useState } from 'react';
function Demo() {
const [value, setValue] = useState(null);
return (
);
}
```
[Documentation](https://mantine.dev/dates/date-time-picker) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/dates/src/components/DateTimePicker)
### DatePicker
Inline date picker component.
```jsx
import { DatePicker } from '@mantine/dates';
import { useState } from 'react';
function Demo() {
const [value, setValue] = useState(null);
return (
);
}
```
[Documentation](https://mantine.dev/dates/date-picker) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/dates/src/components/DatePicker)
### DatePickerInput
Date picker combined with input.
```jsx
import { DatePickerInput } from '@mantine/dates';
import { useState } from 'react';
function Demo() {
const [value, setValue] = useState(null);
return (
);
}
```
[Documentation](https://mantine.dev/dates/date-picker-input) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/dates/src/components/DatePickerInput)
### MonthPicker
Inline month picker component.
```jsx
import { MonthPicker } from '@mantine/dates';
import { useState } from 'react';
function Demo() {
const [value, setValue] = useState(null);
return (
);
}
```
[Documentation](https://mantine.dev/dates/month-picker) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/dates/src/components/MonthPicker)
### MonthPickerInput
Month picker combined with input.
```jsx
import { MonthPickerInput } from '@mantine/dates';
import { useState } from 'react';
function Demo() {
const [value, setValue] = useState(null);
return (
);
}
```
[Documentation](https://mantine.dev/dates/month-picker-input) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/dates/src/components/MonthPickerInput)
### YearPicker
Inline year picker component.
```jsx
import { YearPicker } from '@mantine/dates';
import { useState } from 'react';
function Demo() {
const [value, setValue] = useState(null);
return (
);
}
```
[Documentation](https://mantine.dev/dates/year-picker) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/dates/src/components/YearPicker)
### YearPickerInput
Year picker combined with input.
```jsx
import { YearPickerInput } from '@mantine/dates';
import { useState } from 'react';
function Demo() {
const [value, setValue] = useState(null);
return (
);
}
```
[Documentation](https://mantine.dev/dates/year-picker-input) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/dates/src/components/YearPickerInput)
### TimeInput
Input to capture time from user.
```jsx
import { TimeInput } from '@mantine/dates';
import { useState } from 'react';
function Demo() {
const [value, setValue] = useState(null);
return (
);
}
```
[Documentation](https://mantine.dev/dates/time-input) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/dates/src/components/TimeInput)
## Mantine Charts
The `@mantine/charts` package provides charts and data visualization components based on recharts.
### AreaChart
Display area charts.
```jsx
import { AreaChart } from '@mantine/charts';
function Demo() {
const data = [
{ month: 'January', value: 400 },
{ month: 'February', value: 300 },
{ month: 'March', value: 550 },
{ month: 'April', value: 600 },
{ month: 'May', value: 400 },
{ month: 'June', value: 450 },
];
return (
);
}
```
[Documentation](https://mantine.dev/charts/area-chart) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/charts/src/AreaChart)
### BarChart
Display bar charts.
```jsx
import { BarChart } from '@mantine/charts';
function Demo() {
const data = [
{ month: 'January', value: 400 },
{ month: 'February', value: 300 },
{ month: 'March', value: 550 },
{ month: 'April', value: 600 },
{ month: 'May', value: 400 },
{ month: 'June', value: 450 },
];
return (
);
}
```
[Documentation](https://mantine.dev/charts/bar-chart) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/charts/src/BarChart)
### LineChart
Display line charts.
```jsx
import { LineChart } from '@mantine/charts';
function Demo() {
const data = [
{ month: 'January', value: 400 },
{ month: 'February', value: 300 },
{ month: 'March', value: 550 },
{ month: 'April', value: 600 },
{ month: 'May', value: 400 },
{ month: 'June', value: 450 },
];
return (
);
}
```
[Documentation](https://mantine.dev/charts/line-chart) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/charts/src/LineChart)
### DonutChart
Display donut charts.
```jsx
import { DonutChart } from '@mantine/charts';
function Demo() {
const data = [
{ name: 'USA', value: 600, color: 'indigo.6' },
{ name: 'UK', value: 400, color: 'cyan.6' },
{ name: 'Canada', value: 300, color: 'pink.6' },
];
return (
);
}
```
[Documentation](https://mantine.dev/charts/donut-chart) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/charts/src/DonutChart)
### PieChart
Display pie charts.
```jsx
import { PieChart } from '@mantine/charts';
function Demo() {
const data = [
{ name: 'USA', value: 600, color: 'indigo.6' },
{ name: 'UK', value: 400, color: 'cyan.6' },
{ name: 'Canada', value: 300, color: 'pink.6' },
];
return (
);
}
```
[Documentation](https://mantine.dev/charts/pie-chart) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/charts/src/PieChart)
### Sparkline
Display a simple sparkline chart.
```jsx
import { Sparkline } from '@mantine/charts';
function Demo() {
const data = [10, 20, 40, 20, 40, 10, 50];
return (
);
}
```
[Documentation](https://mantine.dev/charts/sparkline) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/charts/src/Sparkline)
### ScatterChart
Display a scatter chart.
```jsx
import { ScatterChart } from '@mantine/charts';
function Demo() {
const data = [
{ name: 'Point 1', x: 10, y: 10 },
{ name: 'Point 2', x: 20, y: 20 },
{ name: 'Point 3', x: 30, y: 10 },
];
return (
);
}
```
[Documentation](https://mantine.dev/charts/scatter-chart) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/charts/src/ScatterChart)
### BubbleChart
Display a bubble chart.
```jsx
import { BubbleChart } from '@mantine/charts';
function Demo() {
const data = [
{ name: 'Point 1', x: 10, y: 10, size: 10 },
{ name: 'Point 2', x: 20, y: 20, size: 20 },
{ name: 'Point 3', x: 30, y: 10, size: 15 },
];
return (
);
}
```
[Documentation](https://mantine.dev/charts/bubble-chart) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/charts/src/BubbleChart)
### FunnelChart
Display a funnel chart.
```jsx
import { FunnelChart } from '@mantine/charts';
function Demo() {
const data = [
{ name: 'Visited', value: 1000 },
{ name: 'Registered', value: 800 },
{ name: 'Purchased', value: 600 },
{ name: 'Subscribed', value: 400 },
{ name: 'Renewed', value: 200 },
];
return (
);
}
```
[Documentation](https://mantine.dev/charts/funnel-chart) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/charts/src/FunnelChart)
### RadarChart
Display a radar chart.
```jsx
import { RadarChart } from '@mantine/charts';
function Demo() {
const data = [
{ key: 'Group A', metric1: 10, metric2: 20, metric3: 30 },
{ key: 'Group B', metric1: 20, metric2: 10, metric3: 20 },
];
return (
);
}
```
[Documentation](https://mantine.dev/charts/radar-chart) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/charts/src/RadarChart)
### RadialBarChart
Display a radial bar chart.
```jsx
import { RadialBarChart } from '@mantine/charts';
function Demo() {
const data = [
{ name: 'Metric 1', value: 40 },
{ name: 'Metric 2', value: 70 },
{ name: 'Metric 3', value: 30 },
{ name: 'Metric 4', value: 60 },
];
return (
);
}
```
[Documentation](https://mantine.dev/charts/radial-bar-chart) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/charts/src/RadialBarChart)
## Mantine Extensions
### Notifications
Notifications system for Mantine.
```jsx
import { Button } from '@mantine/core';
import { notifications } from '@mantine/notifications';
function Demo() {
return (
);
}
```
[Documentation](https://mantine.dev/x/notifications) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/notifications)
### Spotlight
Command center/search for your application.
```jsx
import { Button } from '@mantine/core';
import { Spotlight, spotlight } from '@mantine/spotlight';
import { IconSearch } from '@tabler/icons-react';
function Demo() {
const actions = [
{
id: 'home',
label: 'Home',
description: 'Get to home page',
onClick: () => console.log('Home'),
},
{
id: 'settings',
label: 'Settings',
description: 'Get to settings page',
onClick: () => console.log('Settings'),
},
];
return (
<>
}
/>
>
);
}
```
[Documentation](https://mantine.dev/x/spotlight) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/spotlight)
### CodeHighlight
Highlight code syntax.
```jsx
import { CodeHighlight } from '@mantine/code-highlight';
function Demo() {
return (
);
}
```
[Documentation](https://mantine.dev/x/code-highlight) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/code-highlight)
### Carousel
Image/content carousel based on Embla.
```jsx
import { Carousel } from '@mantine/carousel';
function Demo() {
return (
123
);
}
```
[Documentation](https://mantine.dev/x/carousel) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/carousel)
### Dropzone
Capture files from user with drag and drop.
```jsx
import { Dropzone } from '@mantine/dropzone';
function Demo() {
return (
console.log('Accepted files', files)}>
Drag files here or click to select files
);
}
```
[Documentation](https://mantine.dev/x/dropzone) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/dropzone)
### Modals Manager
Manage modals state centrally.
```jsx
import { Button } from '@mantine/core';
import { modals } from '@mantine/modals';
function Demo() {
const openConfirmModal = () => modals.openConfirmModal({
title: 'Please confirm your action',
children: 'This action is so important that you need to confirm it.',
labels: { confirm: 'Confirm', cancel: 'Cancel' },
onConfirm: () => console.log('Confirmed'),
});
return ;
}
```
[Documentation](https://mantine.dev/x/modals) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/modals)
### Rich Text Editor
Rich text editor based on Tiptap.
```jsx
import { RichTextEditor, Link } from '@mantine/tiptap';
import { useEditor } from '@tiptap/react';
import StarterKit from '@tiptap/starter-kit';
function Demo() {
const editor = useEditor({
extensions: [
StarterKit,
Link,
],
content: '
Rich text editor content
',
});
return (
);
}
```
[Documentation](https://mantine.dev/x/tiptap) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/tiptap)
### NProgress
Navigation progress component.
```jsx
import { NavigationProgress, nprogress } from '@mantine/nprogress';
function Demo() {
return (
<>
>
);
}
```
[Documentation](https://mantine.dev/x/nprogress) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/nprogress)
## Mantine UI
Mantine UI is a collection of more than 120 responsive components built with Mantine.
[Mantine UI Website](https://ui.mantine.dev) | [GitHub](https://github.com/mantinedev/ui.mantine.dev)
### Application UI Components
Mantine UI provides ready-to-use application UI components such as:
- Navbars (9 components)
- Headers (6 components)
- Footers (4 components)
- Grids (3 components)
- User info and controls (8 components)
- Inputs (14 components)
- Buttons (6 components)
- Sliders (6 components)
- Application cards (7 components)
- Stats (9 components)
- Tables (4 components)
- And more...
### Page Sections
Components for building page sections:
- Hero headers (6 components)
- Features section (5 components)
- Authentication (4 components)
- FAQ sections (4 components)
- Contact sections (3 components)
- Error pages (5 components)
- Banners (3 components)
### Blog UI
Blog-related components:
- Article cards (7 components)
- Table of contents (2 components)
- Comments (2 components)
## Best Practices
1. **Use MantineProvider at the root level** to set up your theme and provide it to all components
2. **Follow the component documentation** for understanding available props and customization options
3. **Utilize the style props system** for one-off styling needs
4. **Use CSS modules or style API** for more complex styling scenarios
5. **Rely on the existing color system** before creating custom colors
6. **Make your application responsive** by using Mantine's responsive props API
7. **Use Mantine hooks** to handle common UI patterns and state management
8. **Combine with Mantine Form** for complex form state management
9. **Use Typescript** to get the best development experience and type safety
10. **Check the documentation** for the latest updates and API changes
## Mantine Hooks
The `@mantine/hooks` package provides utility hooks for common UI patterns.
### UI and DOM Hooks
#### useClickOutside
Detects clicks outside of a specified element.
```jsx
import { useClickOutside } from '@mantine/hooks';
function Demo() {
const ref = useClickOutside(() => console.log('Clicked outside'));
return
This element will detect outside clicks
;
}
```
[Documentation](https://mantine.dev/hooks/use-click-outside) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/hooks/src/use-click-outside/use-click-outside.ts)
#### useColorScheme
Gets user's preferred color scheme using `window.matchMedia`.
```jsx
import { useColorScheme } from '@mantine/hooks';
function Demo() {
const colorScheme = useColorScheme();
return
Preferred color scheme: {colorScheme}
;
}
```
[Documentation](https://mantine.dev/hooks/use-color-scheme) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/hooks/src/use-color-scheme/use-color-scheme.ts)
#### useElementSize
Gets element width and height.
```jsx
import { useElementSize } from '@mantine/hooks';
function Demo() {
const { ref, width, height } = useElementSize();
return
Width: {width}, height: {height}
;
}
```
[Documentation](https://mantine.dev/hooks/use-element-size) | [Source](https://github.com/mantinedev/mantine/tree/master/packages/@mantine/hooks/src/use-element-size/use-element-size.ts)
#### useEventListener
Adds an event listener to the specified element.
```jsx
import { useEventListener } from '@mantine/hooks';
function Demo() {
const ref = useEventListener('keydown', (event) => console.log(event.key));
return