Styles API
With Styles API you can overwrite styles of inner elements in Mantine components with classNames
or
styles
props.
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 |
icon | .mantine-Button-icon | Shared icon styles |
leftIcon | .mantine-Button-leftIcon | Left icon |
rightIcon | .mantine-Button-rightIcon | Right icon |
centerLoader | .mantine-Button-centerLoader | Center loader |
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.
root selector
If component does not specify Styles API selectors, then in most cases you can add styles using root
selector:
Inputs Styles API on MantineProvider
Most of input components are based on Input and Input.Wrapper
components, you can change shared styles on MantineProvider:
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.
Unstyled components
All Mantine components support unstyled
prop which removes all non-essential Mantine styles
from the component. This is useful when you want to add new components styles with Styles API
without overriding default styles.
Unstyled Tabs:
Unstyled Accordion:
Examples
Tabs
Accordion
RangeCalendar
Mo | Tu | We | Th | Fr | Sa | Su |
---|---|---|---|---|---|---|