Styles API
All Mantine components support styling of each component part with inline styles or by passing classes.
Styling with classNames
Let's say you want to make Slider component look like this:
But default slider has completely different styles:
To apply your styles to Slider component, go to "Styles API" tab under component documentation and find styles names table. The name column will tell you how to target a specific element inside the component:
Name | Static selector | Description |
---|---|---|
root | .mantine-Slider-root | Root element |
track | .mantine-Slider-track | Track element, contains all other elements |
bar | .mantine-Slider-bar | Filled part of the track |
thumb | .mantine-Slider-thumb | Main control |
dragging | .mantine-Slider-dragging | Styles added to thumb while dragging |
label | .mantine-Slider-label | Label element, displayed above thumb |
markWrapper | .mantine-Slider-markWrapper | Wrapper around mark, contains mark and mark label |
mark | .mantine-Slider-mark | Mark displayed on the track |
markFilled | .mantine-Slider-markFilled | Styles added to mark when it is located in filled area |
markLabel | .mantine-Slider-markLabel | Mark label, displayed below track |
For example, if you want to add styles to slider thumb:
Now you can write styles for your component with createStyles function or any other styling tools and languages:
Styling with inline styles
Same as in the above example – to make this twitter button you will need to use styles API:
Styles names for button component:
Name | Static selector | Description |
---|---|---|
root | .mantine-Button-root | Root button element |
outline | .mantine-Button-outline | Outline variant root element modifier |
filled | .mantine-Button-filled | Filled variant root element modifier |
light | .mantine-Button-light | Light variant root element modifier |
default | .mantine-Button-default | Default variant root element modifier |
subtle | .mantine-Button-subtle | Default variant root element modifier |
gradient | .mantine-Button-gradient | Gradient variant root element modifier |
white | .mantine-Button-white | White variant root element modifier |
loading | .mantine-Button-loading | Loading root element modifier |
icon | .mantine-Button-icon | Shared icon styles |
leftIcon | .mantine-Button-leftIcon | Left icon |
rightIcon | .mantine-Button-rightIcon | Right icon |
inner | .mantine-Button-inner | Contains label, left and right icons |
label | .mantine-Button-label | Contains button children |
For this button, extra styles are required only for root element and left icon:
Styles API with MantineProvider
You can also use Styles API in MantineProvider with styles
prop.
All styles defined there will be added to each component rendered inside provider.
Static class names
Apart from classNames
and styles
props, each component also has static classes on each element.
You can use them to apply your styles if you do not use CSS modules or just do not want to pass classNames
prop.
More examples
Calendar component
Calendar component customization with styles API:
Mo | Tu | We | Th | Fr | Sa | Su |
---|---|---|---|---|---|---|
Tabs component
Tabs component customization with styles API:
Accordion component
Accordion component customization with styles API: