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 | .asuikit-Slider-root | Root element |
trackContainer | .asuikit-Slider-trackContainer | Wrapper around track, handles drag events |
track | .asuikit-Slider-track | Track element, contains all other elements |
bar | .asuikit-Slider-bar | Filled part of the track |
thumb | .asuikit-Slider-thumb | Main control |
dragging | .asuikit-Slider-dragging | Styles added to thumb while dragging |
label | .asuikit-Slider-label | Label element, displayed above thumb |
marksContainer | .asuikit-Slider-marksContainer | Wrapper around all marks, helps position the marks above the track |
markWrapper | .asuikit-Slider-markWrapper | Wrapper around mark, contains mark and mark label |
mark | .asuikit-Slider-mark | Mark displayed on the track |
markFilled | .asuikit-Slider-markFilled | Styles added to mark when it is located in filled area |
markLabel | .asuikit-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 | .asuikit-Button-root | Root button element |
icon | .asuikit-Button-icon | Shared icon styles |
leftIcon | .asuikit-Button-leftIcon | Left icon |
rightIcon | .asuikit-Button-rightIcon | Right icon |
centerLoader | .asuikit-Button-centerLoader | Center loader |
inner | .asuikit-Button-inner | Contains label, left and right icons |
label | .asuikit-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: